6

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

Community
  • 1
  • 1
Ethan
  • 315
  • 1
  • 3
  • 8
  • 2
    There should be one ```pip``` program for each install of python, so you need to access the one specifically for the newer version – wnnmaw Mar 21 '14 at 14:09
  • can you use virtualenvs? A virtualenv can be initialized using a specific python interpreter, they make it so much easier to manage multiple python versions, and multiple dependencies – dm03514 Mar 21 '14 at 14:15
  • @wnnmaw I only have pip. Not pip-2.6 pip-2.7 etc. When I do `pip install --upgrade pip` I get output `Requirement already up-to-date: pip in /usr/lib/python2.6/site-packages Cleaning up...` – Ethan Mar 21 '14 at 14:16
  • @Ethan, you need two versions of pip, one for each version of Python. And based on that, you have pip-2.6 – wnnmaw Mar 21 '14 at 14:18

1 Answers1

5

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

Forge
  • 6,538
  • 6
  • 44
  • 64
  • Maybe that is the problem. `$ sudo easy_install-2.7 pip sudo: easy_install-2.7: command not found` Please check out this gist https://gist.github.com/Omnipresent/9687245 – Ethan Mar 21 '14 at 14:21
  • You need to verify $PATH is valid and includes the directory of `easy_install-2.7` for root, as well. When switching to root set $PATH to include `easy_install-2.7` directory. – Forge Mar 21 '14 at 14:25
  • 1
    phew I got it to work by giving absolute path: `sudo /usr/local/bin/easy_install-2.7 pip` then `sudo /usr/local/bin/pip2.7 install Wand` Now I can `import wand` successfully. thanks – Ethan Mar 21 '14 at 14:30
  • it's `pip2.7` (no hyphen)...at least with Centos SCL – Dexter Legaspi Sep 29 '14 at 21:07
  • using absolute path like `/usr/local/bin/easy_install` worked! Thanks @Ethan – Mukesh Chapagain Mar 28 '15 at 06:45