New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Relative import doesn't work in debug mode #1523
Comments
Are you sure that this is a Flask issue? Check if http://stackoverflow.com/questions/16981921/relative-imports-in-python-3 helps you. |
No, this is an unfixable bug in Werkzeug. See pallets/werkzeug#461 |
😞 |
@benjamin-hodgson while the bug is "unfixable", there is a solution: don't try to run a Flask app with |
This comment has been minimized.
This comment has been minimized.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I get an exception when I attempt to use a relative import with Flask in debug mode.
Steps to reproduce
My package looks like this:
Here's
__init__.py
:And in
mymodule.py
:Run the application using
python -m mypkg.mymodule
. I'm using Python 3.4.3 on a Windows machine, with Flask 0.10.1 (the version from PyPI).Actual results
The usual "you attempted to use a relative import but you're not in a package" exception:
If you remove
debug=True
, or use an absolute import (from mypkg import xyz
), there is no error. The error persists if you name your module__main__.py
(instead ofmymodule.py
) and usepython -m mypkg
. The error persists if you attempt to import a name from a submodule of the package (it's nothing to do with the import being from__init__.py
).I'm guessing it's something to do with Flask's magical reloading of edited files in debug mode.
Expected results
No error;
xyz
is imported as usual.The text was updated successfully, but these errors were encountered: