Python 在 virtualenv 中安装 Flask 但“找不到命令”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30227360/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Installed Flask in a virtualenv yet "command not found"
提问by Gabriel A. Zorrilla
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.
安装了virtualenv,激活它,pip 安装了flask,但是,当我尝试运行脚本或查看它是否被识别时,我找不到命令。
(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$
采纳答案by dirn
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:
Flask 0.10 没有flask
命令,它是在 0.11 中添加的。如果pi.py
有智慧来运行您的应用程序,例如它使用 Flask-Script,您正在寻找的命令是:
$ python pi.py
You can install Flask-CLIto get the flask
command in 0.10 if you can't upgrade to 0.11.
如果无法升级到 0.11,可以安装Flask-CLI以获取flask
0.10 中的命令。
回答by nscalf
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:
我在运行 0.12 版教程时遇到了这个问题,因此对于发现此线程在更高版本中遇到此问题的人,我能够通过使用以下命令来运行服务器:
$ python -m flask run
回答by Lian
I have used Flask 0.10.1 and to verify whether it's install you should activate the virtualenv and then type:
我已经使用 Flask 0.10.1 并验证它是否已安装,您应该激活 virtualenv 然后键入:
$ 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 :
或使用 flask_script :
from flask_script import Manager
manager = Manager(app)
manager.run
Hope this helps you
希望这对你有帮助
回答by yongyu
I'm using version 0.12.2 and got the same issue.Here is my solution:
我使用的是 0.12.2 版并遇到了同样的问题。这是我的解决方案:
python -m flask run FLASK_APP=/path/to/filename.py
python -m flask run FLASK_APP=/path/to/filename.py
回答by Miguel Ortiz
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.
验证您正在为您的虚拟环境中的正确 Python 版本安装 Flask。
Find out your python version "inside your (venv)"
找出你的python版本“在你的(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
python3的flask安装
pip3 install flask
#or
python3 -m pip install flask
Installation of flask for python2
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)
为默认 python 安装烧瓶(如果你在你的(venv)或你的外壳中,请小心)
pip install flask
python -m install flask
Explanation
解释
For people who run higher versions of Flask consider evaluating your environment as explained here.
对于运行更高版本 Flask 的人,请考虑按照此处的说明评估您的环境。
For me the problem was installing flask for python2 when the binary of my (venv) ran python3.
对我来说,问题是当我的(venv)的二进制文件运行 python3 时为 python2 安装烧瓶。
回答by Ankur Shrivastava
You need to upgrade flask Use the following command on the terminal in your virtual environment
您需要升级flask 在虚拟环境中的终端上使用以下命令
pip install --upgrade Flask
回答by jon
I had to activate again the virtualenv
我不得不再次激活 virtualenv
. venv/bin/activate
This worked for me
这对我有用
回答by Seyed Jalal Hosseini
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.
我有类似的问题。在我的情况下,我已将我的项目移动到另一个目录,并且PATH
仍然指向旧目录。我通过删除我的venv
并创建一个新的来修复它。
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
.
确保您的 env 已激活并检查您的路径echo $PATH
并确保您<user-dir>/<proj-dir>/venv/bin
的PATH
.