~ / archivo / stackoverflow / 51188027
terminal error: flask run zsh: command not found: flask
-
I'm using a Mac , the python version is 2.7.10. and I installed flask
➜ Flask_blog python Python 2.7.10 (default, Oct 6 2017, 22:29:07) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import flask >>>I try to follow the tutorial of flash on http://flask.pocoo.org/docs/1.0/
the commands:
➜ Flask_blog export FLASK_APP=flaskblog.py ➜ Flask_blog flask run zsh: command not found: flask ➜ Flask_blogcode in flaskblog.py:
from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return "Hello World!"The error is
command not found: flaskI also tried an other tutorial.
commands:
➜ Flask_blog cd /Users/jzd/Movies/flask/Second_video ➜ Second_video python one.py Sorrycode in one.py
from flask import Flask app = Flask(__name__) @app.route('/') def index(): return 'Hello World' if __name__ == '__name__': app.run('0.0.0.0') else: print("Sorry")the condition
__name__ == '__name__':did not pass.I guess the python
venvmatters.Really want to know how to fix it.
- Andrejs Cainikovs 2018-07-05 09:45 What is the result of
python -m flask run? You might want to have a look at this. - black_pearl 2018-07-05 10:02 It works @Andrejs Cainikovs. You saved me from three day's pending
- Andrejs Cainikovs 2018-07-05 09:45 What is the result of
-
You could try
python -m flask runinstead.Possible installation issues with
flasknot present, etc, are mentioned in this section of official Flask documentation. -
Verify that the flask path is appended to the $PATH env variable
That might be on the
~/.zshrcor~/.bash_profilefile. Edit the file (nano ~/.zshrc) and add it thereexport PATH=$PATH:/flaskpathThen restart the terminal
-
Verify where you have installed flask:
mortiz@florida:~/Documents/projects$ pip freeze |grep -i flask Flask==1.0.2 mortiz@florida:~/Documents/projects$ pip2 freeze |grep -i flask Flask==1.0.2 mortiz@florida:~/Documents/projects$ pip3 freeze |grep -i flask Flask==1.0.2 Flask-CLI==0.4.0 Flask-Jsonpify==1.5.0 Flask-RESTful==0.3.6 Flask-SQLAlchemy==2.3.2Verify you are installing flask for your correct python version inside your virtual environment.
Find out your python version "inside your (venv)"
mortiz@florida:~/Documents/projects/python/APIS/new_project_py_2_7$ which python /home/mortiz/Documents/projects/python/APIS/new_project_py_2_7/venv/bin/python (venv) mortiz@florida:~/Documents/projects/python/APIS/new_project_py_2_7$ python --version Python 3.5.3Installation of flask for python3
pip3 install flask #or python3 -m pip install flaskInstallation of flask for python2
pip2 install flask #or python2 -m pip install flaskInstallation of flask for default python (be careful if you are inside your (venv) or in your shell)
pip install flask python -m install flaskExplanation
For people who run higher versions of Flask consider evaluating your environment as explained here.
For me the problem was installing flask for python2 when the binary of my (venv) ran python3.
-
maybe you forget, export
FLASK_APPyou can try this commandexport FLASK_APP=<your flask file>.py FLASK_ENV=development && flask runyou can see in documentation
-
When installing flask I saw an error in the end of the installation script saying.
WARNING: The script flask is installed in '/home/doe/.local/bin' which is not on PATH.by doing
echo PATHI indeed verified that that path was not included in my PATH variable.I typed
path+=('/home/doe/.local/bin')andexport PATH.Running
echo PATHagain now included the needed path and thenFLASK_APP=my-app.py flask runworked. -
Leo Gaunt respuesta 2023-09-02 14:39
I found that instead of running
python -m flask runevery time, that when I tried to update the Flask package in pip I was told that where I was installing the packages to wasn't on PATH.I fixed this by running
sudo nano /etc/pathsand adding where my packages were being installed (/Users/XXXXX/Library/Python/3.9/bin) to the end of this list and saving it.This allowed me to run
flask runinstead ofpython3 -m flask run