I have installed flask in a virtual environment as described here https://flask.palletsprojects.com/en/1.1.x/installation/#install-create-env
- Create a directory and run python3 -m venv venv inside the directory to use virtual environment
- Then source venv/bin/activate to activate the environment
- Then pip install flask
Then I created a script like described here https://flask.palletsprojects.com/en/1.1.x/quickstart/
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
Then I added export FLASK_APP=hello.py and ran python3 -m flask run which worked just fine
python3 -m flask run
* Serving Flask app "hello.py"
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
But when I then change FLASK_ENV=development and run the same command I get an error
python3 -m flask run
* Serving Flask app "hello.py" (lazy loading)
* Environment: development
* Debug mode: on
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with stat
/usr/local/opt/python/bin/python3.7: No module named flask
I unset the FLASK_ENV and ran the same command again and everything works as when I did this the first time.