Saltar al contenido

~ / archivo / stackoverflow / 51188027

terminal error: flask run zsh: command not found: flask

StackOverflow · python, flask · ayudé
  1. black_pearl pregunta +4 2018-07-05 09:39

    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.

    • 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
  2. Andrejs Cainikovs respuesta aceptada +14 2018-07-05 11:01

    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.

  3. abinop respuesta +2 2022-10-16 08:43

    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

  4. Miguel Ortiz yo respuesta +1 2018-10-04 19:26

    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.

  5. perymerdeka respuesta +1 2020-12-26 15:33

    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

  6. George Linardis respuesta +1 2021-11-10 16:41

    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.

  7. Leo Gaunt respuesta 2023-09-02 14:39

    I found that instead of running python -m flask run every 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/paths and 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 run instead of python3 -m flask run

← todos los hilos de StackOverflow