Saltar al contenido

~ / archivo / stackoverflow / 30227360

Installed Flask in a virtualenv yet "command not found"

StackOverflow · python, flask, pip, virtualenv · ayudé
  1. Gabriel pregunta +35 2015-05-14 00:22

    Installed virtualenv, activated it, pip installed flask, and yet, when i try to run a script or see if it recognised, i get command not found.

    (project)gabriel@debian:~/project$ pip list
    Flask (0.10.1)
    itsdangerous (0.24)
    Jinja2 (2.7.3)
    MarkupSafe (0.23)
    pip (1.5.6)
    setuptools (5.5.1)
    Werkzeug (0.10.4)
    (project)gabriel@debian:~/project$ flask
    -bash: flask: command not found
    (project)gabriel@debian:~/project$ Flask
    -bash: Flask: command not found
    (project)gabriel@debian:~/project$ </3
    

    Also tried:

    (project)gabriel@debian:~/project$ python -m flask pi.py
    /home/gabriel/project/bin/python: No module named flask.__main__; 'flask' is a package and cannot be directly executed
    (project)gabriel@debian:~/project$ 
    
    • Ciasto piekarz 2017-12-22 04:14 I know this is an old question but still: if you were using virtual env it is possible your environment was messed up, just reinstall and make sure flask executable is there.
  2. dirn respuesta aceptada +26 2015-05-14 01:06

    Flask 0.10 has no flask command, it was added in 0.11. If pi.py has the smarts to run your app, such as if it's using Flask-Script, the command you're looking for is:

    $ python pi.py
    

    You can install Flask-CLI to get the flask command in 0.10 if you can't upgrade to 0.11.

    • Gabriel 2015-05-14 01:41 I was following the tutorial which used an old example instead of the one in the front page. Thank you.
    • Boogie 2019-05-07 16:20 Just uninstall Flask with pip uninstall flask and reinstall with pip install flask. This happened to me after i upgraded pip.
    • AdiAtAnd 2020-06-27 13:03 @dassanctity I didn't get pip install flask anywhere and I came to this thread... I was dying since yesterday for the exact solution to my problem why my flask prog is not running and u saved me.... I installed pip but there was not specific command mentioned to install flask... Maybe I was searching something wrong bit u saved me.. Thanks a ton buddy...
    • dirn 2020-06-27 14:03 @AdiAtAnd you can find the instructions to install Flask at flask.palletsprojects.com/en/1.1.x/installation/#install-fla‌​sk
    • AdiAtAnd 2020-06-27 15:00 Thanks @dirn only thing remaining at my side is setting up environment. My flask prog is already running. Thanks again. 🙂
    • Boogie 2020-07-11 06:41 My pleasure @AdiAtAnd. 😊
  3. nscalf respuesta +36 2017-01-09 20:53

    I ran into this issue while running through the tutorial for version 0.12, so for people who find this thread hitting this issue with a later version, I was able to get the server running by using:

    $ python -m flask run
    
    • Jenya 2021-12-19 12:57 also for python 3 is $python3 -m flask run
    • Honourable Dammy 2026-01-04 13:46 hello i can help you with that
  4. Ankur Shrivastava respuesta +21 2019-02-23 07:31

    You need to upgrade flask Use the following command on the terminal in your virtual environment

    pip install --upgrade Flask
    
    • Hamza Avvan 2019-07-01 18:50 Great! Just upgraded It and was able to use the flask command. Flask@1.0.3
  5. artronics respuesta +5 2020-03-19 12:51

    I had similar issue. In my case I've moved my project to another directory and the PATH was still pointing to the old directory. I fixed it by deleting my venv and creating a new one.

    Make sure your env is activated and check your path echo $PATH and make sure your <user-dir>/<proj-dir>/venv/bin exists in your PATH.

  6. Miguel Ortiz yo respuesta +1 2018-10-04 19:18

    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.

    • mc01 2023-08-14 19:23 For me the problem was assuming pip and pip3 were the same - only pip3 actually installed flask in the venv! pip did ... I don't know what, and put it I don't know where.
    • Miguel Ortiz yo 2023-08-14 19:28 Using 'pip' alone will install anything to the default Python found in your environment. If the default on your environment is python3, then pip probably will install the library for python3. Be careful, venv environment and your shell environment may differ in python versions.
  7. Lian respuesta 2017-01-10 06:38

    I have used Flask 0.10.1 and to verify whether it's install you should activate the virtualenv and then type:

    $ python
    >>> from flask import Flask
    

    if it runs smoothly, you have it. To run the app you can either use

    app = Flask(__name__)
    app.run(debug=True)
    

    or use flask_script :

    from flask_script import Manager
    manager = Manager(app)
    manager.run
    

    Hope this helps you

  8. yongyu respuesta 2017-12-11 12:16

    I'm using version 0.12.2 and got the same issue.Here is my solution:

    python -m flask run FLASK_APP=/path/to/filename.py

  9. jon respuesta 2019-10-31 12:29

    I had to activate again the virtualenv

    . venv/bin/activate
    

    This worked for me

← todos los hilos de StackOverflow