Cannot setup Flask. How to setup environment varia

2020-06-20 16:05发布

I just started learning flask and I am stuck at setting up Flask. I don't know how to setup environment variable. Whenever I use the Flask run command, I encounter the following. I did a lot of google searches to setup environment variable on Windows but I am unable to find and somemtime not able to understand the solution. How to do this ? How to get the "app.py" or "wsgi.py" ? Please help.

command : flask run

Error message : Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory.

error message

标签: python flask
11条回答
冷血范
2楼-- · 2020-06-20 16:33

I used this and it worked because I am doing it in Windows PowerShell.

$env:FLASK_APP = "app.py"

however, flask run didn't and gave me could not import application.

查看更多
疯言疯语
3楼-- · 2020-06-20 16:33

If you're using powershell, make sure you add quotations when setting the environment variable:

$env:FLASK_APP = "app.py

Then flask run should work.

查看更多
甜甜的少女心
4楼-- · 2020-06-20 16:36

hope this could help someone, first set flask env like this inside the python virtual env (for windows command prompt)

set FLASK_ENV = development

then

set FLASK_APP = app.py 

(app.py should be your flask application file)

查看更多
虎瘦雄心在
5楼-- · 2020-06-20 16:36

The similar error was appearing when I was trying to run the application. I have to change the path. I changed directory to the folder where hello.py was saved.

(venv) C:\Users\win10\flask-tutorial\myproject>cd venv
(venv) C:\Users\win10\flask-tutorial\myproject\venv>set FLASK_APP=hello.py
(venv) C:\Users\win10\flask-tutorial\myproject\venv>flask run
查看更多
forever°为你锁心
6楼-- · 2020-06-20 16:39

Windows PowerShell

set FLASK_APP=hello.py
$env:FLASK_APP = "hello.py"
flask run
查看更多
淡お忘
7楼-- · 2020-06-20 16:40

$> set FLASK_APP=application.py $> flask run

查看更多
登录 后发表回答