So, I open a terminal, a CD on my desktop and run:
virtualenv test_env
Then I create the following file in my normal environment:
/home/jesse/.local/lib/python2.6/site-packages/foo_package/__init__.py
This file contains one line:
print "importing from normal env"
In test_env, I create:
/home/jesse/Desktop/test_env/lib/python2.6/site-packages/foo_package/__init__.py
Contains:
print "importing from test env"
Now I open the terminal and run:
$ /home/jesse/Desktop/test_env/bin/python
And then do:
>>> import foo_package
What outputs:
importing from normal env
Why doesn't he import the file from test_env? I thought that was the meaning of the virtual. Did I miss something?
Edit: John X told me that I need to activate the environment. But this does not seem to fix the problem ...
jesse@jesse-laptop :~/Desktop/test_env$ source bin/activate (test_env) jesse@jesse-laptop :~/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 >>>
Using Ubuntu 9.04 / Python 2.6.2 / virtualenv 1.33 in case it is relevant.
Edit 2: Hayes asked me what sys.path was in my virtualenv ...
jesse@jesse-laptop :~/Desktop/test_env$ source bin/activate (test_env) jesse@jesse-laptop :~/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
Output: ['', '/home/jesse/Desktop/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 / l ib / 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 / virtualenvwra pper-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 ']
Edit 3: I found this: https://bugs.launchpad.net/ubuntu/+source/python-virtualenv/+bug/339904 There are apparently some issues with virtualenv + python 2.6 + ubuntu 9.04. Not sure if this is due to my problem ... I tried removing the python-virtualenv package via Synaptic and then installing version 1.3.4 virtualenv via easy_install, but still have the same problem ...
jesse@jesse-laptop :~/Desktop/test_env$ source bin/activate (test_env) jesse@jesse-laptop :~/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']
This looks like a step forward because test_env stuff appears in the way, but it still doesn't work. I think my current problem is that "/home/jesse/.local/lib/python2.6/site-packages" occurs on the way to '/home/jesse/Desktop/test_env/lib/python2.6 / site-packages
Edit 4: Roger suggested creating an env with the -no-site-packages option. I have tried this. Same problem.
jesse@jesse-laptop :~/Desktop/test_env$ source bin/activate (test_env) jesse@jesse-laptop :~/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'] >>>
Again, it seems that the problem is that the site packages in my ".local" appear earlier in the path than the package sites in "test_env".