virtualenv 下的 Python 2.7:损坏的 `site.py`

发布于 2024-11-09 08:53:53 字数 1622 浏览 2 评论 0原文

当我使用 Python 2.7 创建一个新的 virtualenv 时,我无法使用 site.getsitepackages()

$ virtualenv testenv -p python2.7 --no-site-packages
Running virtualenv with interpreter /usr/bin/python2.7
New python executable in testenv/bin/python2.7
Also creating executable in testenv/bin/python
Installing setuptools............done.
Installing pip...............done.
$ cd testenv/
$ source bin/activate
(testenv)$ python
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import site
>>> site.getsitepackages()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>

AttributeError: 'module' object has no attribute 'getsitepackages'

似乎 site.py 没有 Python 2.7 中应有的新函数。

有什么建议吗?

编辑:即使我不使用 --no-site-packages 问题仍然存在:

$ virtualenv testenv -p python2.7
Running virtualenv with interpreter /usr/bin/python2.7
New python executable in testenv/bin/python2.7
Also creating executable in testenv/bin/python
Installing setuptools............done.
Installing pip...............done.
$ cd testenv/
$ source bin/activate
(testenv)$ python
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import site
>>> site.getsitepackages()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'getsitepackages'

When I create a fresh virtualenv with Python 2.7 I cannot use site.getsitepackages():

$ virtualenv testenv -p python2.7 --no-site-packages
Running virtualenv with interpreter /usr/bin/python2.7
New python executable in testenv/bin/python2.7
Also creating executable in testenv/bin/python
Installing setuptools............done.
Installing pip...............done.
$ cd testenv/
$ source bin/activate
(testenv)$ python
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import site
>>> site.getsitepackages()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>

AttributeError: 'module' object has no attribute 'getsitepackages'

It seems site.py does not have new functions that should be there from Python 2.7.

Any suggestions?

EDIT: Even if I don't use --no-site-packages the problem remains:

$ virtualenv testenv -p python2.7
Running virtualenv with interpreter /usr/bin/python2.7
New python executable in testenv/bin/python2.7
Also creating executable in testenv/bin/python
Installing setuptools............done.
Installing pip...............done.
$ cd testenv/
$ source bin/activate
(testenv)$ python
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import site
>>> site.getsitepackages()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'getsitepackages'

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

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

发布评论

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

评论(3

诺曦 2024-11-16 08:53:53

这是 virtualenv 更高版本中修复的错误。我查遍了门票,但没有找到合适的......

It was a bug fixed in later versions of virtualenv. I searched through the tickets, but I could not find the right one...

自由如风 2024-11-16 08:53:53

您正在使用 --no-site-packages,这会导致新环境不继承现有的站点包。

You are using --no-site-packages, which causes the new environment to not inherit existing site-packages.

鸢与 2024-11-16 08:53:53

也许这不是导致你的问题的原因,但它在 4 小时的调试后帮助了我(而且我在 1 年后回答了这个问题:)。

virtualenv/bin/python 文件必须是可执行的。

所以...

chmod +x virtualenv/bin/python

在这里工作。

Probably this is not what is causing your problem, but it helped me after 4 hours of debugging (also I'm answering the question 1 year later :).

The virtualenv/bin/python file must be executable.

So...

chmod +x virtualenv/bin/python

worked here.

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