当我用 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'