Python 使用flask执行hello world“ImportError:没有名为flask的模块”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34785690/
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
execute hello world with flask "ImportError: No module named flask"
提问by Lindages
I'm trying to use flask and python. I did a simple file named hello.py
. tHis file contains this code:
我正在尝试使用烧瓶和 python。我做了一个名为hello.py
. tHis 文件包含以下代码:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def main():
return "Welcome!"
if __name__ == "__main__":
app.run()
This is a simple hello world with flask. I want to execute it but actually, I have a problem. In the terminal, I typed python hello.py
and I get this error:
这是一个带有烧瓶的简单 hello world。我想执行它,但实际上,我遇到了问题。在终端中,我输入python hello.py
并收到此错误:
File "hello.py", line 1, in <module>
from flask import Flask
ImportError: No module named flask
Even that I installed flask globally. I understand that this is a basic question, but I'm stuck?
即使我在全球安装了烧瓶。我知道这是一个基本问题,但我被卡住了?
回答by Tomasz Jakub Rup
You don't have installed flask
你还没有安装 flask
Linux:
Linux:
Install flask
as global package:
安装flask
为全局包:
sudo pip install flask
Install in virtualenv
在 virtualenv 中安装
virtualenv venv
source venv
pip install flask
Install system package
安装系统包
debian, ubuntu
apt-get install python-flask
arch
pacman -S python-flask
fedora
yum install python-flask
Debian, Ubuntu
apt-get install python-flask
拱
pacman -S python-flask
软呢帽
yum install python-flask
Install via Anaconda
通过Anaconda安装
conda install flask
Windows:
视窗:
python -m pip install flask
回答by Ata
You've installed flask for python2 you need to use sudo pip3 install ... to get it for python3. I had spent a day when I got that I was using pip for python 2.
你已经为 python2 安装了烧瓶,你需要使用 sudo pip3 install ... 来为 python3 获取它。我花了一天的时间才知道我正在将 pip 用于 python 2。