Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask_APP environment variable not found

Tags:

python

flask

I'm a beginner to Flask and I ran into some errors. about how I did not provide the Flask_APP environment variable:

Error: 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 have this error with flask when I try and run my flask code. My code was working at first but then when I tried running it again it had this problem. I searched everywhere for help but I could only find ones about powershell. I'm currently using Ubuntu. Thank you!

like image 541
mark Avatar asked Nov 08 '25 09:11

mark


1 Answers

In order to run a flask app using the flask command in the terminal, you need to set an environment variable in that terminal. For example, if your app is created in my_app.py, then you need to execute the following in your terminal:

export FLASK_APP=my_app.py

If you restart the terminal at any point you will need to re-export this variable.

You can check if it is set in your current terminal using:

echo $FLASK_APP

which will show nothing if unset or my_app.py if set as above.

like image 89
PirateNinjas Avatar answered Nov 09 '25 23:11

PirateNinjas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!