2

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 flasktutorial.py in the directory.

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

* Serving Flask app "flasktutorial"
* Forcing debug mode on
* Running on http://127.0.0.1:5000/ (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.

Zavec
  • 195
  • 2
  • 10
  • An out of scope advice: switch your OS to Linux. It will pay back the time you'll spend on it. Now you are going to be solving the side-effects of using Windows as your Python development environment. – Igor Jun 30 '16 at 11:41

1 Answers1

4

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

python -m flask run

Explanation:

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.

aholik
  • 76
  • 3