2011-05-21 43 views
4

當我創建與Python 2.7新的virtualenv我不能使用site.getsitepackages()的Python 2.7下的virtualenv:破`site.py`

$ 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' 

回答

1

這是在virtualenv的更高版本中修復的錯誤。我搜索了通過門票,但我找不到合適的...

+0

其實這個bug還沒有修復:( [實際錯誤(關閉爲DUP)]](https://github.com/pypa/virtualenv/issues/228),[Parent](https://github.com/ pypa/virtualenv中/問題/ 355) – 2013-03-20 11:22:43

0

您正在使用--no-site-packages,這將導致新的環境中不能承受現有站點包。

+1

是的,但問題是'site'模塊沒有'getsitepackages()'函數,在Python 2.7中添加。 – rubik 2011-05-21 15:49:16

+0

您是否嘗試刪除env,然後嘗試不使用「--no-site-packages」?我遇到了同樣的問題,但刪除env後再次嘗試運行。 – ubik 2011-05-21 17:08:07

+0

是的,問題仍然存在,請參閱我的編輯。 – rubik 2011-05-22 08:54:37

0

也許這不是什麼導致你的問題,但它幫助我經過4個小時的調試(也是我回答了1年後的問題:)。

virtualenv/bin/python文件必須是可執行文件。

所以......

chmod +x virtualenv/bin/python 

在這裏工作。

相關問題