Flask can't find app file
Question:
In Step 2 of the official Flask tutorial, Flask cannot find my app file because it’s looking in ../venv/Scripts/
instead of where I run the command. How can I tell Flask to look in the right place?
(venv) C:UsersTomVCodesflaskr_tutorial>flask run
* Serving Flask app "flaskr"
* Forcing debug mode on
* Restarting with stat
c:userstomvcodesflaskr_tutorialvenvscriptspython.exe: can't open file 'C:UsersTomVCodesflaskr_tutorialvenvScriptsflask': [Errno 2] No such file or directory
Answers:
There seems to a bug according to this github issue:
https://github.com/pallets/flask/issues/1829
As a workaround you can do
>python -m flask run
You can also use >python -m flask initdb
later in the tutorial, when initializing the database (step 4).
You can give full path to app.py when you run “python app.py”
python C:/path/to/file/app.py
I just want to leave this solution for whom other solutions aren’t working.
Assuming here the module "app" is actually referring to your "app.py" source file, in the app.run() ensure to set debug to FALSE i.e. app.run(debug=False)
. Otherwise cd
to the folder in which your app.py file is and then run python app.py
These are workarounds, but it seems there is a bug in the debug=True flow as old as 2016-17, perhaps it hasn’t been fixed yet
In Step 2 of the official Flask tutorial, Flask cannot find my app file because it’s looking in ../venv/Scripts/
instead of where I run the command. How can I tell Flask to look in the right place?
(venv) C:UsersTomVCodesflaskr_tutorial>flask run
* Serving Flask app "flaskr"
* Forcing debug mode on
* Restarting with stat
c:userstomvcodesflaskr_tutorialvenvscriptspython.exe: can't open file 'C:UsersTomVCodesflaskr_tutorialvenvScriptsflask': [Errno 2] No such file or directory
There seems to a bug according to this github issue:
https://github.com/pallets/flask/issues/1829
As a workaround you can do
>python -m flask run
You can also use >python -m flask initdb
later in the tutorial, when initializing the database (step 4).
You can give full path to app.py when you run “python app.py”
python C:/path/to/file/app.py
I just want to leave this solution for whom other solutions aren’t working.
Assuming here the module "app" is actually referring to your "app.py" source file, in the app.run() ensure to set debug to FALSE i.e. app.run(debug=False)
. Otherwise cd
to the folder in which your app.py file is and then run python app.py
These are workarounds, but it seems there is a bug in the debug=True flow as old as 2016-17, perhaps it hasn’t been fixed yet