pip 安装在全局站点包而不是 virtualenv [英] pip installing in global site-packages instead of virtualenv

查看:35
本文介绍了pip 安装在全局站点包而不是 virtualenv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 pip3virtualenv 中安装包会导致包安装在全局 site-packages 文件夹中,而不是安装在 virtualenv 文件夹中.以下是我在 OS X Mavericks (10.9.1) 上设置 Python3 和 virtualenv 的方法:

Using pip3 to install a package in a virtualenv causes the package to be installed in the global site-packages folder instead of the one in the virtualenv folder. Here's how I set up Python3 and virtualenv on OS X Mavericks (10.9.1):

我使用 Homebrew 安装了 Python3:

I installed Python3 using Homebrew:

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
brew install python3 --with-brewed-openssl

改变了.bash_profile中的$PATH变量;添加了以下行:

Changed the $PATH variable in .bash_profile; added the following line:

export PATH=/usr/local/bin:$PATH

运行 which python3 返回 /usr/local/bin/python3(重新启动 shell 后).

Running which python3 returns /usr/local/bin/python3 (after restarting the shell).

注意:which python3 仍然返回/usr/bin/python.

Note: which python3 still returns /usr/bin/python though.

使用pip3安装virtualenv:

pip3 install virtualenv

接下来,创建一个新的virtualenv并激活它:

Next, create a new virtualenv and activate it:

virtualenv testpy3 -p python3
cd testpy3
source bin/activate

注意:如果我不指定 -p python3,virtualenv 中的 bin 文件夹中将缺少 pip.

运行 which pipwhich pip3 都返回 virtualenv 文件夹:

Running which pip and which pip3 both return the virtualenv folder:

/Users/kristof/VirtualEnvs/testpy3/bin/pip3

现在,当我尝试安装时,例如Markdown 在激活的 virtualenv 中使用 pip,pip 将安装在全局的 site-packages 文件夹中,而不是安装在 virtualenv 的 site-packages 文件夹中.

Now, when I try to install e.g. Markdown using pip in the activated virtualenv, pip will install in the global site-packages folder instead of the site-packages folder of the virtualenv.

pip install markdown

运行 pip list 返回:

Markdown (2.3.1)
pip (1.4.1)
setuptools (2.0.1)
virtualenv (1.11)

/Users/kristof/VirtualEnvs/testpy3/lib/python3.3/site-packages的内容:

__pycache__/
_markerlib/
easy_install.py
pip/
pip-1.5.dist-info/
pkg_resources.py
setuptools/
setuptools-2.0.2.dist-info/

/usr/local/lib/python3.3/site-packages的内容:

Markdown-2.3.1-py3.3.egg-info/
__pycache__/
easy-install.pth
markdown/
pip-1.4.1-py3.3.egg/
setuptools-2.0.1-py3.3.egg
setuptools.pth
virtualenv-1.11-py3.3.egg-info/
virtualenv.py
virtualenv_support/

如您所见,global site-packages 文件夹包含 Markdown,而 virtualenv 文件夹不包含.

As you can see, the global site-packages folder contains Markdown, the virtualenv folder doesn't.

注意:我之前在不同的 VM 上安装了 Python2 和 Python3(遵循 这些 指令)并且在 Python3 上有同样的问题;不过,在基于 Python2 的 virtualenv 中安装包可以完美无缺.

Note: I had Python2 and Python3 installed before on a different VM (followed these instructions) and had the same issue with Python3; installing packages in a Python2 based virtualenv worked flawlessly though.

任何提示、提示……将不胜感激.

Any tips, hints, … would be very much appreciated.

推荐答案

我遇到了同样的问题,我通过删除 venv 目录并重新创建它来解决它!

I had the same problem, I solved it by removing venv directory and recreating it!

deactivate (if venv is activated first deactivate it)
rm -rf venv
virtualenv -p python3 venv
. ENV/bin/activate
pip3 install -r requirements.txt

现在一切都像一个魅力.

Now everything works like a charm.

这篇关于pip 安装在全局站点包而不是 virtualenv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆