Reputation: 13695
I need to use python on a big server where I don't have root access. I want to use a newer version of numpy than the one that is installed globally on the machine. virtualenv
is designed exactly for this purpose, and I create my virtual environment and activate it with the following commands:
virtualenv my_personal_python
source my_personal_python/bin/activate
I then install the new version of the library that I'm interested in using
pip install numpy==1.6.0
The problem is that when I now import numpy it still imports the outdated global version, not the one install in the virtual environment's my_personal_python/lib/python2.6/site-packacges
directory.
I am already aware of one possible solution, the --no-site-packages flag, as in:
virtualenv --no-site-packages my_personal_python
When I use this flag then the import behaves as I desire. But I don't want to use this flag because I do not want to re-install all packages locally, I just want to override a couple of them.
(I'm using python 2.6, virtualenv 1.6.1, and the PYTHONPATH variable on my machine is not set.)
Update Even if I add the site-packages directory from the virtual environment to the beginning of the python path, numpy does not get imported from this location (although other packages are imported from this location). Maybe this problem is specific to numpy and does not occur with packages in general.
Upvotes: 27
Views: 17282
Reputation: 4632
One more solution to this problem (helped me, at least): In my ~/.local/lib/python2.7/site-packages/easy-install.pth
, there were (IMHO unnecessary) lines like /usr/lib/python2.7/dist-packages
. Removing these lines helped, maybe they were left over from much older times, when easy_install still did stranger things.
Upvotes: 2
Reputation: 1644
This worked for me.
My which python
and which pip
were exactly correct but the sys.path
was wrong. My virtualenv is in ~/virtualenvs/envy
. Originally I was doing:
export PYTHONPATH=~/virtualenvs/envy/lib/python2.7/site-packages:$PYTHONPATH
but this still was importing the system-wide package instead of my virtualenv one. BUT I watched this PyCon talk on virtualenv and decided to try:
export PYTHONPATH=~/virtualenvs/envy/lib/python2.7:$PYTHONPATH
Notice the lack of site-packages
in the second option. And this actually worked! I hope it helps someone else.
Upvotes: 4
Reputation: 32392
Double check a few things.
which python
which pip
Now that you are sure you are running the right one, start python and:
import sys
print "\n".join(sys.path)
Then exit python and type echo $PATH
followed by echo $PYTHONPATH
I suspect that the problem will be visible and if you cannot fix it by setting PYTHONPATH
then you can likely do it with the site
module.
Upvotes: 9