Python 没有使用 virtualenv 的名为烧瓶的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20414015/
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
No module named flask using virtualenv
提问by user1668814
I am following these steps to learn flask http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world/page/0#comments
我正在按照这些步骤学习烧瓶http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world/page/0#comments
I ran this command to create the virtual env:
我运行这个命令来创建虚拟环境:
python virtualenv.py flask
When I try to start flask using the python.exe file in my project scripts directory, it says
当我尝试使用项目脚本目录中的 python.exe 文件启动烧瓶时,它说
No module named flask
My PATH is set to the python directory that virtualenv installed. Why is it not able to find flask?
我的 PATH 设置为 virtualenv 安装的 python 目录。为什么找不到flask?
I initially started with the official Flask quickstart guide and was able to get the webserver to run, but with this virtual env install it is not working.
我最初从官方的 Flask 快速入门指南开始,并且能够让网络服务器运行,但是使用这个虚拟环境安装它不起作用。
采纳答案by user1668814
Make sure your virtualenv is activated. Then You check on the PYTHONPATHof that virtualenv. Is there a flask package (folder) installed in that directory.
确保您的 virtualenv 已激活。然后你检查PYTHONPATH那个 virtualenv 的。该目录中是否安装了烧瓶包(文件夹)。
If you unsure whether you have installed flask, just run the following command to see all the packages you have installed pip listor pip show flask. Do you see flask there? If not you can run pip install flask
如果不确定是否安装了flask,只需运行以下命令即可查看已安装的所有包pip list或pip show flask. 你看到那里的烧瓶了吗?如果没有你可以运行pip install flask
回答by sreisman
Activate your virtual environment first with
首先激活您的虚拟环境
source bin/activate envName
Then try to run your command again
然后尝试再次运行您的命令
回答by mumush
Make sure you run your script afteryou've activated your virtualenv. On OS X you'd see (virtual_env_name)at the start of each terminal line. To do this:
确保在激活 virtualenv后运行脚本。在 OS X 上,您会(virtual_env_name)在每个终端行的开头看到。去做这个:
cdto your virtualenv's directory and type . bin/activate
cd到您的 virtualenv 目录并键入 . bin/activate
cdto the directory containing the .pyfile you want to run at app launch in the browser
cd到包含.py要在浏览器中启动应用程序时运行的文件的目录
Now enter python file_name.py, for me the file name was routes.pyfollowing this example
现在输入python file_name.py,对我来说文件名routes.py遵循这个例子
回答by Carl James
On Windows even if you see (virtual_env_name) in the cmd line it is possible that the virtual environment is not completely activated. Deactivate/reactivate and try again.
在 Windows 上,即使您在 cmd 行中看到 (virtual_env_name),也可能虚拟环境未完全激活。停用/重新激活并重试。
回答by Martlark
This error can also appear if you start your Flask python server using ./run.pyor similarly use file associations to start your server. Then the python command in the association will be used instead of your virtual environment python command. Use python run.pyinstead. See how my run.py innocently assumes /usr/bin/python?
如果您使用./run.py或类似地使用文件关联来启动您的Flask python 服务器,也会出现此错误。然后将使用关联中的 python 命令而不是你的虚拟环境 python 命令。使用python run.py来代替。看看我的 run.py 是如何无辜地假设 /usr/bin/python 的?
#!/usr/bin/python
# run.py
from app import app
app.run(debug=True,host='0.0.0.0',port=5000)
回答by thirdangle
I am running Python on windows 7. I had same problem No module named flask.
我在 Windows 7 上运行 Python。我有同样的问题 没有名为flask 的模块。
I tried reinstalling python, venv but it did not work.
我尝试重新安装 python、venv,但没有用。
Finally i run it like this
最后我像这样运行它
- Install venv the usual way
- go to scripts directory and activate
- C:\Python34\microb>c:\Python34\microb\fla\scripts\python run.py
- here microb is my project and fla is venv
- 以通常的方式安装 venv
- 转到脚本目录并激活
- C:\Python34\microb>c:\Python34\microb\fla\scripts\python run.py
- 这里 microb 是我的项目,fla 是 venv
回答by Sanyam Jain
This problem can also arise if the port is not available. Try running on different port.
如果端口不可用,也会出现此问题。尝试在不同的端口上运行。
回答by jmaybe
I had this same problem on three Raspberry Pi units at the same time; beat my head against the wall trying to fix it for several hours (reinstall flask via pip, apt and aptitude - no joy).
我同时在三个 Raspberry Pi 单元上遇到了同样的问题;把我的头撞在墙上试图修复它几个小时(通过 pip、apt 和 aptitude 重新安装烧瓶 - 没有乐趣)。
Instead of:
代替:
pip install flask
I finally tried:
我终于试过了:
pip install Flask
Worked like a charm.
像魅力一样工作。
回答by Denis Rasulev
If nothing else helps, check that in your code it is:
如果没有其他帮助,请检查您的代码是否为:
from flask import Flask
I've tried many things before I've noticed my mistake. I had this in my code:
在我注意到我的错误之前,我已经尝试了很多事情。我的代码中有这个:
from Flask import Flask
When I have changed capitalized letter for the module name, i.e. flaskthen everything worked.
当我更改了模块名称的大写字母时,即flask一切正常。
回答by singh.jitendra
In Python 3.x
在 Python 3.x 中
pip3 install flask
Worked fine for me.
对我来说效果很好。
Thanks & Regards
感谢和问候

![[:-1] 在 python 中是什么意思/做什么?](/res/img/loading.gif)