'Why does running `flask run` on Windows result in "flask is not recognized as an internal or external command, operable program or batch file"

I needed to setup Flask for windows, so I ran the following commands:

set FLASK_APP=application.py
set FLASK_DEBUG=1
set DATABASE_URL='postgres.......' =>(the credential given by the Heroku account)
flask run

But when I hit enter on the flask run, I get an error that says -

flask is not recognized as an internal or external command, operable program or batch file

Why is this not working? I've been trying to work on it but I'm still having the same error message.

What could be the issue?



Solution 1:[1]

Try using:

python -m flask run 

Also make sure you are in the same directory as application.py

Solution 2:[2]

Maybe you are working in another directory where the Flask is not installed.

Just install Flask on the current directory:

pip install flask

Solution 3:[3]

I faced the same issue. Perhaps you missed the message you received while installing 'flask'. While running pip install flask I received

WARNING: The script flask.exe is installed in 'C:\Users\ankur.kulshrestha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\Scripts' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

Either set the path in your PATH env variable or use the complete path while running flask run.

Solution 4:[4]

I had this same issue and resolved it by running this in CMD, where the path is set to your Python scripts folder:

set PATH=C:\Users\YOUR_USER_NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\Scripts

The error is related to the "WARNING" that may be shown when running 'pip install flask'. You can also confirm whether you installed flask successfully by using 'pip show flask'.

Solution 5:[5]

If you have Anaconda, use python -m flask run from Anaconda Prompt when you are on the folder of the script app.py.

Solution 6:[6]

uninstall flask using the following command

pip uninstall flask

close cmd and open cmd as Administrator now run

pip install flask

check:

flask --version

Solution 7:[7]

Make sure you've saved the application.py and the app variable exists.

then run python -m flask run ,

Solution 8:[8]

install flask: pip install flask in the working directory where application.py file is located.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 kidbilly
Solution 2 Gino Mempin
Solution 3 KnowledgeSeeeker
Solution 4 allan200
Solution 5 shahar_m
Solution 6 Zoe stands with Ukraine
Solution 7 sule mohammed
Solution 8 Ramu