How to get pip to point to newer version of Python

2019-06-20 04:37发布

问题:

I have two versions of Python installed on my centOS server.

[ethan@demo ~]$ python2.6 --version
Python 2.6.6
[ehtan@demo ~]$ python --version
Python 2.7.3

The older version (2.6) is required by some essential centOS packages so I can't remove it.

When I install packages using pip, they are being installed in Python 2.6. But instead I want them to be installed to Python 2.7.

How can I change this behaviour?

For example, here is what happened when I tried installing Wand

[ethan@demo ~]$ pip install Wand
Requirement already satisfied (use --upgrade to upgrade): Wand in /usr/lib/python2.6/site-packages
Cleaning up...
[ethan@demo ~]$ python2.6
Python 2.6.6 (r266:84292, Jul 10 2013, 22:48:45) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import wand
>>> exit()
[ethan@demo ~]$ python
Python 2.7.3 (default, Oct 11 2013, 15:59:28) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import wand
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named wand
>>> exit()

Edit

I found this answer but it didn't work for me https://stackoverflow.com/a/4910393/3384340

回答1:

You need to install pip for each python version separately.

In order to install pip for Python2.7, run

sudo easy_install-2.7 pip

Use pip-2.7 to install Wand

sudo pip-2.7 install Wand