python – 使用Virtualenv安装Flask

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

我好像很迷茫.首先从我的理解.运行命令’python virtualenv.py flask’在文件夹’flask’中创建一个虚拟python环境.它是否正确?

第二,这是不是意味着如果我cd到这个文件夹然后运行’pip install flask’它应该将flask安装到该文件夹​​?当我运行任何这些pip安装命令时,我的终端充满了疯狂的疯狂,我不明白.

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:

知道我做错了什么吗?

最佳答案 您需要首先在新的flask文件夹中获取bin / activate脚本以激活virtualenv.

如果你正在运行bash(最有可能),那么运行:

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

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

deactivate

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

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

点赞