Virtualenv 不使用全局包

发布于 2024-11-15 17:57:22 字数 928 浏览 2 评论 0原文

请帮助诊断 virtualenv 问题。它想要下载并安装 numpy 和 lxml,而全局站点包中有符合版本要求的已安装版本。

$ virtualenv venv # not restricting access to site-packages
...

$ . venv/bin/activate
(venv)$ python -c 'import numpy; print numpy._version_; print numpy.__file__'
1.5.1
/usr/lib/pymodules/python2.7/numpy/_init_.pyc

(venv)$ grep numpy setup.py
'numpy>=1.5.1',

(venv)$ python setup.py develop
...
Searching for numpy==1.5.1 # Why exact ==1.5.1? Where is it from?
Reading http://pypi.python.org/simple/numpy/
Reading http://numpy.scipy.org
Reading http://sourceforge.net/project/showfiles.php?group_id=1369&package_id=175103
Reading http://numeric.scipy.org
Best match: numpy 1.5.1
Downloading http://pypi.python.org/packages/source/n/numpy/numpy-1.5.1.tar.gz#md5=376ef150df41b5353944ab742145352d

版本:Ubuntu 11.04、Python 2.7.1+、virtualenv 1.4.9

更新:virtualenv 1.5.1 及更高版本按预期工作。还是很好奇到底出了什么问题。

Please help to diagnose virtualenv problem. It wants to download and install numpy and lxml, while there are installed versions in global site-packages that match version requirements.

$ virtualenv venv # not restricting access to site-packages
...

$ . venv/bin/activate
(venv)$ python -c 'import numpy; print numpy._version_; print numpy.__file__'
1.5.1
/usr/lib/pymodules/python2.7/numpy/_init_.pyc

(venv)$ grep numpy setup.py
'numpy>=1.5.1',

(venv)$ python setup.py develop
...
Searching for numpy==1.5.1 # Why exact ==1.5.1? Where is it from?
Reading http://pypi.python.org/simple/numpy/
Reading http://numpy.scipy.org
Reading http://sourceforge.net/project/showfiles.php?group_id=1369&package_id=175103
Reading http://numeric.scipy.org
Best match: numpy 1.5.1
Downloading http://pypi.python.org/packages/source/n/numpy/numpy-1.5.1.tar.gz#md5=376ef150df41b5353944ab742145352d

Versions: Ubuntu 11.04, Python 2.7.1+, virtualenv 1.4.9

Upd: virtualenv 1.5.1 and newer works as expected. Still curious what was the problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

调妓 2024-11-22 17:57:22

根据提出这个问题的时间,我的答案无法解决OP所遇到的问题,但我遇到了类似的问题并提出了这个问题。我弄清楚了我的问题是什么,所以我将这个答案发布给后代和任何遇到此问题的其他人。

从 virtualenv 1.7 开始 --no-site-packages 成为默认行为。要使全局站点包可导入(这曾经是默认设置),您必须在创建 virtualenv 时使用选项 --system-site-packages。

Based on when this question was asked, my answer would not solve the issue the OP had, but I was having a similar problem and came upon this question. I figured out what my problem was so I am posting this answer for posterity and anyone else who runs across this.

Starting with virtualenv 1.7 --no-site-packages became the default behavior. To make global site packages importable (which used to be the default) you must use the option --system-site-packages when you create the virtualenv.

倾城泪 2024-11-22 17:57:22

此错误是由于 virtualenv 的发布版本(ubuntu 中为 1.4.9
11.04)。该版本没有复制virtualenv中python安装的目录config/,所以sysconfig,在python2.7中引入
坏了。

这是一种解决方法:

mkdir -p <VIRTUALENV_PATH>/local/lib/python2.7/config/
cp /usr/lib/python2.7/config/Makefile <VIRTUALENV_PATH>/local/lib/python2.7/config/Makefile

https://bugs.launchpad.net/ ubuntu/+source/python-virtualenv/+bug/780220

This bug is due to the shipped version of virtualenv (1.4.9 in ubuntu
11.04). This version does not copy the directory config/ of the python installation in the virtualenv, so sysconfig, introduced in python2.7
is broken.

Here is a workaround:

mkdir -p <VIRTUALENV_PATH>/local/lib/python2.7/config/
cp /usr/lib/python2.7/config/Makefile <VIRTUALENV_PATH>/local/lib/python2.7/config/Makefile

https://bugs.launchpad.net/ubuntu/+source/python-virtualenv/+bug/780220

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文