3

我正在尝试遵循以下教程 http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world#commentform

我似乎很失落。首先根据我的理解。运行命令“python virtualenv.py flask”会在文件夹“flask”中创建一个虚拟 python 环境。这个对吗?

其次,这是否意味着如果我 cd 到这个文件夹然后运行“pip install flask”它应该将烧瓶安装到那个文件夹?当我运行任何这些 pip install 命令时,我的终端充满了我不理解的疯狂。

Benjamins-MacBook:flask test$ pip install flask==0.9
Downloading/unpacking flask==0.9
Downloading Flask-0.9.tar.gz (481kB): 481kB downloaded
Running setup.py egg_info for package flask

warning: no files found matching '*' under directory 'tests'
warning: no previously-included files matching '*.pyc' found under directory 'docs'
warning: no previously-included files matching '*.pyo' found under directory 'docs'
warning: no previously-included files matching '*.pyc' found under directory 'tests'
warning: no previously-included files matching '*.pyo' found under directory 'tests'
warning: no previously-included files matching '*.pyc' found under directory 'examples'
warning: no previously-included files matching '*.pyo' found under directory 'examples'
no previously-included directories found matching 'docs/_build'
no previously-included directories found matching 'docs/_themes/.git'
Downloading/unpacking Werkzeug>=0.7 (from flask==0.9)
Downloading Werkzeug-0.9.4.tar.gz (1.1MB): 1.1MB downloaded
Running setup.py egg_info for package Werkzeug

warning: no files found matching '*' under directory 'werkzeug/debug/templates'
warning: no files found matching '*' under directory 'tests'
warning: no previously-included files matching '*.pyc' found under directory 'docs'
warning: no previously-included files matching '*.pyo' found under directory 'docs'
warning: no previously-included files matching '*.pyc' found under directory 'tests'
warning: no previously-included files matching '*.pyo' found under directory 'tests'
warning: no previously-included files matching '*.pyc' found under directory 'examples'
warning: no previously-included files matching '*.pyo' found under directory 'examples'
no previously-included directories found matching 'docs/_build'
Downloading/unpacking Jinja2>=2.4 (from flask==0.9)
Downloading Jinja2-2.7.1.tar.gz (377kB): 377kB downloaded
Running setup.py egg_info for package Jinja2

warning: no files found matching '*' under directory 'custom_fixers'
warning: no previously-included files matching '*' found under directory 'docs/_build'
warning: no previously-included files matching '*.pyc' found under directory 'jinja2'
warning: no previously-included files matching '*.pyc' found under directory 'docs'
warning: no previously-included files matching '*.pyo' found under directory 'jinja2'
warning: no previously-included files matching '*.pyo' found under directory 'docs'
Downloading/unpacking markupsafe (from Jinja2>=2.4->flask==0.9)
Downloading MarkupSafe-0.18.tar.gz
Running setup.py egg_info for package markupsafe

Installing collected packages: flask, Werkzeug, Jinja2, markupsafe
Running setup.py install for flask

warning: no files found matching '*' under directory 'tests'
warning: no previously-included files matching '*.pyc' found under directory 'docs'
warning: no previously-included files matching '*.pyo' found under directory 'docs'
warning: no previously-included files matching '*.pyc' found under directory 'tests'
warning: no previously-included files matching '*.pyo' found under directory 'tests'
warning: no previously-included files matching '*.pyc' found under directory 'examples'
warning: no previously-included files matching '*.pyo' found under directory 'examples'
no previously-included directories found matching 'docs/_build'
no previously-included directories found matching 'docs/_themes/.git'
error: could not create '/Library/Python/2.7/site-packages/flask': Permission denied
Complete output from command /usr/bin/python -c "import          setuptools;__file__='/private/var/folders/9l/6fgb2st97cs2b2jkj7g4bs5m0000gp/T/pip_build_test/flask/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/9l/6fgb2st97cs2b2jkj7g4bs5m0000gp/T/pip-PbWDVv-record/install-record.txt --single-version-externally-managed:

知道我做错了什么吗?

4

3 回答 3

7

您需要bin/activate首先在新的烧瓶文件夹中获取脚本以激活 virtualenv。

如果您正在运行bash(很可能),则运行:

cd new/flask/directory
. bin/activate
pip install ...

当你想退出 virtualenv 时,你可以退出终端选项卡,或者运行:

deactivate

请注意,当您激活 virtualenv 时,它仅在您所在的一个终端选项卡中处于活动状态。

如果您不先运行该命令,pip则将尝试安装到您的系统目录中,从而给出您看到的权限错误。

于 2013-08-28T02:47:47.573 回答
0

错误说:error: could not create '/Library/Python/2.7/site-packages/flask': Permission denied这意味着您需要root权限才能安装flask。尝试sudo pip install flask==0.9

于 2015-04-21T06:20:09.117 回答
0

virtualenv 必须在创建后激活。

切换到刚刚创建的 virtualenv 目录,并从 bin 目录获取激活脚本:

$ source flask/bin/activate

另外,在这里查看第一个答案:尝试安装 Flask 0.9 后的警告和错误

于 2013-08-28T09:22:40.673 回答