於是我打開一個終端,cd到我的桌面,然後運行:的virtualenv混亂
virtualenv test_env
然後我在我的正常環境中創建以下文件:
/home/jesse/.local/lib/python2.6/site-packages/foo_package/__init__.py
此文件包含一行:
print "importing from normal env"
在test_env創建:
/home/jesse/Desktop/test_env/lib/python2.6/site-packages/foo_package/__init__.py
包含:
print "importing from test env"
現在我打開一個終端,運行:
$ /home/jesse/Desktop/test_env/bin/python
然後執行:
>>> import foo_package
,輸出:
爲什麼不將它導入從test_env文件?我認爲這是virtualenv的重點。我在這裏錯過了什麼嗎?
編輯:喬恩H告訴我,我需要激活環境。但這似乎不能解決問題...
[email protected]:~/Desktop/test_env$ source bin/activate
(test_env)[email protected]:~/Desktop/test_env$ bin/python
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import foo_package
importing from normal env
>>>
使用Ubuntu 9.04/Python 2.6.2/virtualenv 1.33以防萬一。
編輯2:黑斯問我,是我的virtualenv什麼sys.path中......
[email protected]:~/Desktop/test_env$ source bin/activate
(test_env)[email protected]:~/Desktop/test_env$ bin/python
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
輸出: [ '',「/家庭/傑西/桌面/ test_env/lib中/ python2 .6/site-packages/setuptools-0.6c9-py2.6.egg','/usr/local/lib/python2.6/dist-packages/enum-0.4.3-py2.6.egg','/ usr/local/lib/python2.6/dist-packages/clonedigger-1.0.9_beta-py2.6.egg','/usr/local/lib/python2.6/dist-packages/ETS-3.2.0-py2 .6.egg','/usr/local/lib/python2.6/dist-packages/TraitsGUI-3.0.4-py2.6.egg','/usr/local/lib/python2.6/dist-packages /TraitsBackendWX-3.1.0-py2.6.egg','/usr/local/lib/python2.6/dist-packages/TraitsBackendQt-3.1.0-py2.6.egg' ,'/usr/local/lib/python2.6/dist-packages/yolk-0.4.1-py2.6.egg','/usr/local/lib/python2.6/dist-packages/pylint-0.18。 0-py2.6.egg','/usr/local/lib/python2.6/dist-packages/logilab_astng-0.19.0-py2.6.egg','/usr/local/lib/python2.6/ dist-packages/logilab_common-0.39.0-py2.6.egg','/usr/local/lib/python2.6/dist-packages/pudb-0.92.7-py2.6.egg','/ usr/local/lib/python2.6/dist-packages/Pygments-1.0-py2.6.egg','/usr/local/lib/python2.6/dist-packages/ETSProjectTools-0.5.1-py2.6.egg ','/usr/local/lib/python2.6/dist-packages/pydee-0.4.24-py2.6.egg','/usr/local/lib/python2.6/dist-packages/visionegg-1.2 .1-py2.6-linux-i686.egg','/usr/local/lib/python2.6/dist-packages/PyOpenGL-3.0.0c1-py2.6.egg','/ usr/local/lib /python2.6/dist-packages/Whoosh-0.2.6-py2.6。egg','/usr/local/lib/python2.6/dist-packages/pyinotify-0.8.6-py2.6.egg','/usr/local/lib/python2.6/dist-packages/svgbatch- 0.1.9-py2.6.egg','/usr/local/lib/python2.6/dist-packages/pyglet-1.1.3-py2.6.egg','/ usr/local/lib/python2。 6/dist-packages/lepton-1.0b2-py2.6-linux-i686.egg','/usr/local/lib/python2.6/dist-packages/rope-0.9.2-py2.6.egg' ,'/usr/local/lib/python2.6/dist-packages/simplejson-2.0.9-py2.6-linux-i686.egg','/usr/local/lib/python2.6/dist-packages/ pymunk-0.8.4-py2.6.egg','/usr/local/lib/python2.6/dist-packages/cssutils-0.9.6-py2.6.egg','/ usr/local/lib/python2.6/dist-packages/Shapely-1.0.14-py2.6.egg','/usr/local/lib/python2.6/dist-packages/sympy-0.6.5-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/virtualenvwrapper-1.20-py2.6.egg','/home/jesse/Desktop/test_env/lib/python2.6','/ home/jesse/Desktop/test_env/lib/python2.6/plat-linux2','/home/jesse/Desktop/test_env/lib/python2.6/lib-tk','/ home/jesse/Desktop/test_env/lib/python2。 6/lib-old','/ home/jesse/Desktop/test_ env/lib/python2.6/lib-dynload','/usr/lib/python2.6','/usr/lib/python2.6/plat-linux2','/usr/lib/python2.6/lib -tk','/home/jesse/.local/lib/python2.6/site-packages','/home/jesse/Desktop/test_env/lib/python2.6/site-packages','/ usr/local /lib/python2.6/dist-packages','/usr/lib/python2.6/dist-packages','/usr/lib/python2.6/dist-packages/Numeric','/ usr/lib/python2.6/dist-packages/PIL','/usr/lib/python2.6/dist-packages/gst-0.10','/var/lib/python-support/python2.6','/ usr/lib /python2.6/dist-packages/gtk-2.0','/var/lib/python-support/python2.6/gtk-2.0','/usr/lib/python2.6/dist-packages/wx-2.8 -gtk2-unicode']
編輯3:我發現這個:https://bugs.launchpad.net/ubuntu/+source/python-virtualenv/+bug/339904顯然有一些virtualenv + python 2.6 + ubuntu 9.04的問題。如果這是與我的問題不知道......我試圖卸載通過突觸蟒蛇-的virtualenv包和virtualenv中通過的easy_install然後安裝版本1.3.4,但仍然有同樣的問題...
[email protected]:~/Desktop/test_env$ source bin/activate
(test_env)[email protected]:~/Desktop/test_env$ bin/python
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import foo_package
importing from normal env
>>> import sys
>>> print sys.path
['', '/home/jesse/Desktop/test_env/lib/python2.6/site-packages/setuptools-0.6c9-py2.6.egg', '/home/jesse/Desktop/test_env/lib/python2.6', '/home/jesse/Desktop/test_env/lib/python2.6/plat-linux2', '/home/jesse/Desktop/test_env/lib/python2.6/lib-tk', '/home/jesse/Desktop/test_env/lib/python2.6/lib-old', '/home/jesse/Desktop/test_env/lib/python2.6/lib-dynload', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/home/jesse/.local/lib/python2.6/site-packages', '/home/jesse/Desktop/test_env/lib/python2.6/site-packages', '/usr/local/lib/python2.6/dist-packages/enum-0.4.3-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/clonedigger-1.0.9_beta-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/ETS-3.2.0-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/TraitsGUI-3.0.4-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/TraitsBackendWX-3.1.0-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/TraitsBackendQt-3.1.0-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/yolk-0.4.1-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/pylint-0.18.0-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/logilab_astng-0.19.0-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/logilab_common-0.39.0-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/pudb-0.92.7-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/Pygments-1.0-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/ETSProjectTools-0.5.1-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/pydee-0.4.24-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/visionegg-1.2.1-py2.6-linux-i686.egg', '/usr/local/lib/python2.6/dist-packages/PyOpenGL-3.0.0c1-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/Whoosh-0.2.6-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/pyinotify-0.8.6-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/svgbatch-0.1.9-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/pyglet-1.1.3-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/lepton-1.0b2-py2.6-linux-i686.egg', '/usr/local/lib/python2.6/dist-packages/rope-0.9.2-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/simplejson-2.0.9-py2.6-linux-i686.egg', '/usr/local/lib/python2.6/dist-packages/pymunk-0.8.4-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/cssutils-0.9.6-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/Shapely-1.0.14-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/sympy-0.6.5-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/virtualenvwrapper-1.20-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/virtualenv-1.3.4-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/enum-0.4.3-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/ETS-3.2.0-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/yolk-0.4.1-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/Whoosh-0.2.6-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/pyinotify-0.8.6-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/pyglet-1.1.3-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/simplejson-2.0.9-py2.6-linux-i686.egg', '/usr/local/lib/python2.6/site-packages', '/usr/local/lib/python2.6/site-packages/gtk-2.0', '/usr/local/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages/Numeric', '/usr/lib/python2.6/dist-packages/PIL', '/usr/lib/python2.6/dist-packages/gst-0.10', '/var/lib/python-support/python2.6', '/usr/lib/python2.6/dist-packages/gtk-2.0', '/var/lib/python-support/python2.6/gtk-2.0', '/usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode']
這看起來像是前進的一步,因爲test_env
東西出現在路徑中,但它仍然不起作用。我認爲我目前的問題是'/home/jesse/.local/lib/python2.6/site-packages'出現在'/home/jesse/Desktop/test_env/lib/python2.6/site-packages '
編輯4:羅傑建議使用--no-site-packages選項創建env。我試過了。同樣的問題。
[email protected]:~/Desktop/test_env$ source bin/activate
(test_env)[email protected]:~/Desktop/test_env$ bin/python
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import foo_package
importing from normal env
>>> import sys
>>> sys.path
['', '/home/jesse/Desktop/test_env/lib/python2.6/site-packages/setuptools-0.6c9-py2.6.egg', '/home/jesse/Desktop/test_env/lib/python2.6', '/home/jesse/Desktop/test_env/lib/python2.6/plat-linux2', '/home/jesse/Desktop/test_env/lib/python2.6/lib-tk', '/home/jesse/Desktop/test_env/lib/python2.6/lib-old', '/home/jesse/Desktop/test_env/lib/python2.6/lib-dynload', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/home/jesse/.local/lib/python2.6/site-packages', '/home/jesse/Desktop/test_env/lib/python2.6/site-packages']
>>>
再次,它看起來像這個問題是在我的「當地的」站點包更早出現在比‘test_env’的站點包的路徑。
什麼是您的virtualenv設置爲sys.path? – Haes 2009-10-26 13:18:00
我在上面添加了這些信息,請參閱編輯2. – 2009-10-26 19:11:48