I just started learning flask and I am stuck at setting up the Flask environment variables. I don\'t know how to setup the environment variables. Whenever I use the flask
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)
I don't think the 'flask run' command is the one which causes the error here.
I got the same message error and the problem came from the fact I copied/pasted the set FLASK_APP
and $env: FLASK_APP
commands as written in the documentation. I had to add spaces before and after '>' or '=', and then everything worked.
Example: this command didn't work 'C:\path\to\app>set FLASK_APP=hello.py'
, but this one did 'C:\path\to\app > set FLASK_APP = hello.py'
.
Maybe it's the same problem you have?
You need to actually run it from your Windows command line, NOT the built in command line for something like Visual Studio Code. Run those commands from your windows command line, in the proper directory, and everything should work.
The reason this creates problems - Visual Studio Code creates a Powershell environment for your command line. You could use the recommended $env:FLASK_APP = "your_app.py" from within the VSC environment and that will work too.
A bit late but I hope this helps others!!!
Try using app.py instead of different name
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.
My error was also same but fortunately I was able to resolve it. Here you go,
D:\Development\Projects\Python_Projects\flask_blog>set FLASK_APP=app.py
D:\Development\Projects\Python_Projects\flask_blog>$env:FLASK_APP = "app.py"
D:\Development\Projects\Python_Projects\flask_blog>python -m flask run