我对瓶子依赖性感到满意如下。
indikau@ruhuna ~ $ sudo -H python -m pip install flask
Requirement already satisfied (use --upgrade to upgrade): flask in /usr/local/lib/python2.7/dist-packages
Requirement already satisfied (use --upgrade to upgrade): itsdangerous>=0.21 in /usr/local/lib/python2.7/dist-packages (from flask)
Requirement already satisfied (use --upgrade to upgrade): click>=2.0 in /usr/local/lib/python2.7/dist-packages (from flask)
Requirement already satisfied (use --upgrade to upgrade): Werkzeug>=0.7 in /usr/local/lib/python2.7/dist-packages (from flask)
Requirement already satisfied (use --upgrade to upgrade): Jinja2>=2.4 in /usr/local/lib/python2.7/dist-packages (from flask)
Requirement already satisfied (use --upgrade to upgrade): MarkupSafe>=0.23 in /usr/lib/python2.7/dist-packages (from Jinja2>=2.4->flask)
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
indikau@ruhuna ~ $ ls
这是我的代码。
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello() -> str:
return 'Hello Flask!'
app.run()
我能够创建一个新的virtualenv。
indikau@ruhuna ~/Documents/head_first_python/chapter04 $ virtualenv flask
Using base prefix '/usr'
New python executable in /home/indikau/Documents/head_first_python/chapter04/flask/bin/python3.5
Also creating executable in /home/indikau/Documents/head_first_python/chapter04/flask/bin/python
Installing setuptools, pip, wheel...done.
indikau@ruhuna ~/Documents/head_first_python/chapter04 $ which flask
/usr/local/bin/flask
但我仍然收到以下错误。
indikau@ruhuna ~/Documents/head_first_python/chapter04 $ python hello.py
Traceback (most recent call last):
File "hello.py", line 1, in <module>
from flask import Flask
ImportError: cannot import name 'Flask'
任何人都可以帮助我吗? (我在python3.x上)
答案 0 :(得分:0)
如果您要使用virtualenv,则必须激活虚拟环境。在virtualenv flask
之后执行以下代码:
source /home/indikau/Documents/head_first_python/chapter04/flask/bin/activate
并在虚拟环境瓶中重新安装烧瓶。