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.
I used this and it worked because I am doing it in Windows PowerShell.
however,
flask run
didn't and gave me could not import application.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.hope this could help someone, first set flask env like this inside the python virtual env (for windows command prompt)
then
(app.py should be your flask application file)
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.
Windows PowerShell
$> set FLASK_APP=application.py $> flask run