2016-08-12 71 views
0

我快VIRTUALENV這樣的:Virtualenv包含全球套餐/我如何清除我的PYTHONPATH?

$ virtualenv --no-site-packages venv 
New python executable in .../venv/bin/python 
Installing setuptools, pip, wheel...done. 
$ source venv/bin/activate 

但是,當我pip freeze -l,我沒有得到任何東西。所以我雙重檢查我的PYTHONPATH

$ python 
import sys 
for i in sys.path: 
...  print i 

這給了這樣的輸出:

/home/... 
/usr/local/lib/python2.7/site-packages 
/usr/local/lib/python2.7/dist-packages 
/usr/lib/python2.7/site-packages 
/usr/lib/python2.7/dist-packages 
/home/.../venv/lib/python2.7 
/home/.../venv/lib/python2.7/plat-x86_64-linux-gnu 
/home/.../venv/lib/python2.7/lib-tk 
/home/.../venv/lib/python2.7/lib-old 
/home/.../venv/lib/python2.7/lib-dynload 
/usr/lib/python2.7 
/usr/lib/python2.7/plat-x86_64-linux-gnu 
/usr/lib/python2.7/lib-tk 
/home/.../venv/local/lib/python2.7/dist-packages 
/home/.../venv/lib/python2.7/site-packages 
/home/.../venv/local/lib/python2.7/dist-packages 

在目錄中,我用...的路徑表示我的項目/工作目錄。

在我看來,我真正需要做的是確保在我的虛擬環境中,/usr/路徑不顯示。但我該怎麼做?我如何清除這些無關的路徑?

回答

0

我不知道這是一個很好的修復,但我發現在我的.bashrc幾條語句:

export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages 
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/dist-packages 
export PYTHONPATH=$PYTHONPATH:/usr/lib/python2.7/site-packages 
export PYTHONPATH=$PYTHONPATH:/usr/lib/python2.7/dist-packages 

這一點我註釋掉,然後這些路徑不再sys.path露面。現在我的virtualenv正在按照需要工作,但我很想知道爲什麼這會真正解決問題。

相關問題