Python 导入错误:没有名为烧瓶的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24188240/
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
ImportError: No module named flask
提问by leandrotk
I installed virtualenv, activated it, and installed flask. So I have three folders: Include, Scripts and Lib. This last folder contains the site-packages folder, that contains flask folder.
我安装了 virtualenv,激活它,并安装了 Flask。所以我有三个文件夹:Include、Scripts 和 Lib。最后一个文件夹包含 site-packages 文件夹,其中包含 Flask 文件夹。
If I put my app.py (simple Hello World app) inside "site-packages" folder, I don't get this error. But if put out of this three folder, but inside my flask_environment, I get this error.
如果我将 app.py(简单的 Hello World 应用程序)放在“site-packages”文件夹中,则不会出现此错误。但是如果把这三个文件夹放在外面,但是在我的flask_environment里面,我会得到这个错误。
Is something going wrong here?
这里有什么问题吗?
The error:
错误:
Traceback (most recent call last):
File "C:\Flask\flask_env\app.py", line 3, in <module>
from flask import Flask
ImportError: No module named flask
回答by Dhananjay
Please make sure you have activated virtual environment before running python file.
在运行 python 文件之前,请确保您已激活虚拟环境。
. venv/bin/activate
回答by Najeebullah Shah
check this stack answer, only instead of pika you have to type flask:
检查这个堆栈答案,只有你必须输入flask而不是pika:
回答by FrozZerrer
If you are using python3 you have to change a little bit your wsgi file.
如果您使用的是 python3,则必须稍微更改您的 wsgi 文件。
I changed my xx.wsgi from using execfile() to using exec(). Here is what it looks like when it finally worked.
我将 xx.wsgi 从使用 execfile() 更改为使用 exec()。这是它最终工作时的样子。
activate_this = '/opt/flask/project_name/py3venv/bin/activate_this.py'
exec(open(activate_this).read(), dict(__file__=activate_this))
import sys
sys.path.insert(0, '/opt/flask/project_name')
from project_app_name import app as application
回答by ablshk
try this command in the terminal instead of selecting 'run code':
在终端中尝试此命令,而不是选择“运行代码”:
python3 'insert your file name here without the quotes'
回答by F.A. SULAIMAN
run as python3 <file_name>
运行方式 python3 <file_name>
EX: python3 api.py
例如:python3 api.py