views:

66

answers:

3

Hi, I have a problem with virtualenv. I use it regulary, I use it on my development machine and on several servers. But on this last server I tried to use i got a problem.

I created a virtualenv with the --no-site-packages argument, and then I installed some python modules inside the virtualenv. I can confirm that the modules is located inside the virtualenvs site-packages and everything seems to be fine.

But when i try to do:source virtualenv/bin/activate and then import one of the module python import modulename i get an import error that says that the module doesnt exist. How is it that this is happending? It seems like it never activates even thoug that it says it do.

Anybody have a clue on how to fix this?

A: 

IIRC, the activate script just puts your virtual env first on your path, so when you type "python" it finds the one in your virtual env first. If the activate script fails, you can always edit your path manually. Also - go here and search for "activate": http://pylonsbook.com/en/1.1/installing-pylons.html#setting-up-a-virtual-python-environment. This will tell you why the activate command can fail.

Jeff Peck
+1  A: 

Is there a bash alias active on this machine for "python", by any chance? That will take priority over the PATH-modifications made by activate, and could cause the wrong python binary to be used.

Try running virtualenv/bin/python directly (no need to activate) and see if you can import your module.

If this fixes it, you just need to get rid of your python bash alias.

Carl Meyer
Thanks, that was it. Couldnt figure out what the reason was. Do you now how to make this a permanent change so that i dont have to do venv/bin/python everytime?
Espen Christensen
A: 

After activating the virtual env, try:

$ python
>>> import sys
>>> sys.executable
...

... and see if you are running the expected executable.

Also check:

>>> sys.path
[...]
codeape