Flask fails to start with use_reloader=True when using absolute import
See original GitHub issueI’m using Flask v0.10.1 and I have the following project structure:
test
├── api
│ ├── hello.py
│ └── __init__.py
├── config
│ ├── config.py
│ └── __init__.py
└── __init__.py
The hello.py file is:
import sys
import flask
from test.config import config
app = flask.Flask(__name__)
@app.route('/hello')
def hello():
return config.MESSAGE
def main(argv):
reloader = '--reloader' in argv
print('Starting with reloader={}'.format(reloader))
app.run(host='0.0.0.0', port=8080, debug=True, use_reloader=reloader)
if __name__ == '__main__':
main(sys.argv)
and the config.py is simply
MESSAGE = 'Hello!'
When I run api.py
with use_reloader=False
(python -m test.api.hello
) the server starts correctly. If I run it with use_reloader=True
(python -m test.api.hello --reloader
) it fails with:
Starting with reloader=True
* Running on http://0.0.0.0:8080/
* Restarting with reloader
Traceback (most recent call last):
File "/home/kostas/Tmp/testproj/test/api/hello.py", line 3, in <module>
from test.config import config
ImportError: No module named config
Issue Analytics
- State:
- Created 9 years ago
- Comments:14 (5 by maintainers)
Top Results From Across the Web
Unable to import flask app folder in unittest folder of an repo
I have tried the following after checking a few resources of absolute and relative imports, none of them worked. from .. import app....
Read more >Flask absolute import bug in debug mode - Chase Seibert Blog
I was getting errors trying to use absolute imports in a new flask app: ... It turned out that setting debug=False fixed the...
Read more >How we improved our Python backend start-up time - Medium
Two months ago, it was taking around 10 seconds for our backend to start the application on a developer's machine, and around 12...
Read more >API — Flask Documentation (2.2.x)
Relative to the application root_path or an absolute path. ... When using flask run to start the development server, an interactive debugger will...
Read more >Flask-Testing 0.3 documentation - PythonHosted.org
from flask import Flask from flask_testing import TestCase class ... be set to 0 to have the underlying operating system pick an open...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I personally fixed this using the following in my equivalent of
hello.py
:Just do that before you call
app.run()
with the reloader enabled; that seems to fix it for me.The current solution is to avoid running your app via
python -m ...
.The issue I linked above contains all the details and why this is an unfixable problem AFAIK
On 18 June 2015 11:59:41 CEST, “Piotrek Szymański” notifications@github.com wrote: