user3666820 user3666820 - 1 year ago 199
Python Question

Flask: Restarting with reloader can't find file

I'm trying to learn flask. I've created a virtual environment (venv) in my project directory (C:\users\ian\git\flasktutorial). FLASK_APP is set to flasktutorial, FLASK_DEBUG=1, and I do have a in the directory.

When I type "flask run" I get the following:

* Serving Flask app "flasktutorial"
* Forcing debug mode on
* Running on (Press CTRL+C to quit)
* Restarting with windowsapi reloader
c:\users\ian\git\flasktutorial\venv\scripts\python.exe: can't open file 'C:\users\Ian\Git\flasktutorial\venv\Scripts\flask': [Errno 2] No such file or directory

Checking that folder, it does seem to have a flask.exe in it. Not sure what's going on here.

Answer Source

Run flask as a module, then the reloader will work on Windows:

python -m flask run


When starting the app in Windows with flask.exe then the reloader constructs wrong args for the new subprocess. Source code here.

It tries to run the python interpreter with flask.exe as script name, but without the extension, this is the the reason for the file not found error. If you make a dupe and copy Scripts/flask.exe to Scripts/flask then it will work. ;)

Otherwise, when running flask as a module then the sys.argv contains proper paths for the reloader to run the subprocess.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download