virtualenv 下的 Python 2.7:损坏的 `site.py`
当我使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是 virtualenv 更高版本中修复的错误。我查遍了门票,但没有找到合适的......
It was a bug fixed in later versions of virtualenv. I searched through the tickets, but I could not find the right one...
您正在使用
--no-site-packages
,这会导致新环境不继承现有的站点包。You are using
--no-site-packages
, which causes the new environment to not inherit existing site-packages.也许这不是导致你的问题的原因,但它在 4 小时的调试后帮助了我(而且我在 1 年后回答了这个问题:)。
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...
worked here.