Reputation: 3779
I installed version 2.7.3, and whenever I type:
import numpy
I get an error message saying I don't have it installed. but when I run python 2.6, it imports it beautifully. The same happens with all my previous libraries : scipy, numpy, cv,cv2, networkx. I think it has to do with switching the python library path for the new default version. How do I do this?
Upvotes: 3
Views: 4436
Reputation: 69
I had this problem for CentOS 6, as it uses python 2.6 for the system and Yum depends on it. My workaround was to temporarily rename the /usr/bin/python
binary to something else (e.g., /usr/bin/orig-python
). Then I made a link to the python 2.7 installation:
ln -s /usr/local/bin/python2.7 /usr/bin/python
And voilà, it worked perfectly.
This works in case you have a stubborn program that won't take the settings in your $PATH
because normally you should be able to execute the correct python if it is configured in your path.
Upvotes: 1
Reputation: 8370
If you download the numpy source, untar, and cd to the numpy directory, and type (as root)
python2.7 setup.py install
python 2.7 will install numpy in its own area. Same should apply for the other modules you mention.
The problem is that most installers will just look for python
, which is linked to whatever your Ubuntu installation uses by default. In theory you could do something like
sudo cp -f $(which python2.7) $(which python)
to overwrite this link, but overwriting your system default python installation is a very bad idea and will almost certainly break something.
Upvotes: 1
Reputation: 20419
Python sys.path
will hold list of path where it needs to look to import a library, in case you are confident that libraries installed in python2.6
will work in python2.7
, you need to update sys.path
every time you load interpreter.
In case you are using GNU/Linux you can add export PATH=/path/to/py2.6/library:$PATH
to ~/.bashrc.
It advised to use pip
and install all your libraries in python2.7 .
http://www.pip-installer.org/en/latest/index.html
Since python2.7
and python2.6
are installed, carefully use them while installing libraries.
[EDIT]
$ curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py
$ python get-pip.py
and start using pip-2.7
or pip
accordingly.
Upvotes: 3
Reputation: 11383
You have to install the library separately for each python version. These libraries aren't shared and shouldn't be shared between different version of python.
Upvotes: 4