Installed Flask in a virtualenv yet “command not found”

后端 未结 8 904
暗喜
暗喜 2020-12-14 19:36

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)gabri         


        
8条回答
  •  天涯浪人
    2020-12-14 20:02

    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.

提交回复
热议问题