Python Forum

Full Version: Running flask run produces error.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I'm following a tutorial on Flask development on Windows 10.
I installed virtual environment and install flask.

Then I exported this:
FLASK_ENV=development
FLASK_APP=main.py

Then while in virtualenv I typed:
flask run

(env) J:\Web Projects\enrollment>flask run
* Serving Flask app "main.py" (lazy loading)
* Environment: development
* Debug mode: on
* Restarting with stat
j:\envs\env\scripts\python.exe: No module named J:\Envs\env\Scripts\flask

However if I do this:
python -m flask run
everything works.

I've done a lot of searching with no success.
What am I doing wrong?

Python: 3.7.3
Flask: 1.1.1

Thanks in advance for any help.
(Oct-04-2019, 10:06 AM)Charles1 Wrote: [ -> ]Then I exported this:
You most use set on Windows,and venv is build into Python no install.
Example.
C:\code
λ python -m venv flask_env

C:\code
λ cd flask_env\

C:\code\flask_env
λ C:\code\flask_env\Scripts\activate

(flask_env) C:\code\flask_env
λ set FLASK_APP=app.py

(flask_env) C:\code\flask_env
λ flask run
 * Serving Flask app "app.py"
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [05/Oct/2019 00:16:57] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [05/Oct/2019 00:16:57] "GET /favicon.ico HTTP/1.1" 404 -
Not fan of setting environment variable like this.
python-dotenv fix this as it bring into project and not use OS path.
From Flask 1.0 --> there is build in support for python-dotenv.