terminal error: flask run zsh: command not found: flask
Question:
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_blog
code in flaskblog.py:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
The error is command not found: flask
I also tried an other tutorial.
commands:
➜ Flask_blog cd /Users/jzd/Movies/flask/Second_video
➜ Second_video python one.py
Sorry
code 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 venv
matters.
Really want to know how to fix it.
Answers:
You could try python -m flask run
instead.
Possible installation issues with flask
not present, etc, are mentioned in this section of official Flask documentation.
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.2
Verify 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.3
Installation of flask for python3
pip3 install flask
#or
python3 -m pip install flask
Installation of flask for python2
pip2 install flask
#or
python2 -m pip install flask
Installation of flask for default python (be careful if you are inside your (venv) or in your shell)
pip install flask
python -m install flask
Explanation
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_APP
you can try this command
export FLASK_APP=<your flask file>.py FLASK_ENV=development && flask run
you 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 PATH
I indeed verified that that path was not included in my PATH variable.
I typed path+=('/home/doe/.local/bin')
and export PATH
.
Running echo PATH
again now included the needed path and then FLASK_APP=my-app.py flask run
worked.
Verify that the flask path is appended to the $PATH env variable
That might be on the ~/.zshrc
or ~/.bash_profile
file. Edit the file (nano ~/.zshrc
) and add it there
export PATH=$PATH:/flaskpath
Then restart the terminal
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_blog
code in flaskblog.py:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
The error is command not found: flask
I also tried an other tutorial.
commands:
➜ Flask_blog cd /Users/jzd/Movies/flask/Second_video
➜ Second_video python one.py
Sorry
code 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 venv
matters.
Really want to know how to fix it.
You could try python -m flask run
instead.
Possible installation issues with flask
not present, etc, are mentioned in this section of official Flask documentation.
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.2
Verify 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.3
Installation of flask for python3
pip3 install flask
#or
python3 -m pip install flask
Installation of flask for python2
pip2 install flask
#or
python2 -m pip install flask
Installation of flask for default python (be careful if you are inside your (venv) or in your shell)
pip install flask
python -m install flask
Explanation
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_APP
you can try this command
export FLASK_APP=<your flask file>.py FLASK_ENV=development && flask run
you 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 PATH
I indeed verified that that path was not included in my PATH variable.
I typed path+=('/home/doe/.local/bin')
and export PATH
.
Running echo PATH
again now included the needed path and then FLASK_APP=my-app.py flask run
worked.
Verify that the flask path is appended to the $PATH env variable
That might be on the ~/.zshrc
or ~/.bash_profile
file. Edit the file (nano ~/.zshrc
) and add it there
export PATH=$PATH:/flaskpath
Then restart the terminal