Import error with virtualenv
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 th开发者_运维技巧at 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?
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.
After activating the virtual env, try:
$ python
>>> import sys
>>> sys.executable
...
... and see if you are running the expected executable.
Also check:
>>> sys.path
[...]
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.
精彩评论