Installed Flask in a virtualenv yet “command not found”

后端 未结 8 883
暗喜
暗喜 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 19:52

    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.

    0 讨论(0)
  • 2020-12-14 19:59

    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

    0 讨论(0)
  • 2020-12-14 20:02

    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.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-14 20:03

    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

    0 讨论(0)
  • 2020-12-14 20:05

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

    pip install --upgrade Flask
    
    0 讨论(0)
提交回复
热议问题