Flask_APP environment variable not found

Question:

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!

Asked By: mark

||

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.

Answered By: PirateNinjas

Once in your project directory run the command below will solve your problem

flask --app app.py db init

Where app.py is your flask application file name.

Answered By: KIMBOH LOVETTE
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.