如何让pip指向更新版本的Python

时间:2014-03-21 14:06:04

标签: python python-2.7 pip python-2.6

我的Python服务器上安装了两个centOS版本。

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

某些必要的centOS软件包需要旧版本(2.6),因此我无法将其删除。

当我使用pip安装软件包时,它们将安装在Python 2.6中。但我希望将它们安装到Python 2.7

如何更改此行为?

例如,以下是我尝试安装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()

修改

我找到了这个答案,但它对我不起作用https://stackoverflow.com/a/4910393/3384340

1 个答案:

答案 0 :(得分:5)

你需要分别为每个python版本安装pip。

要为Python2.7安装pip,请运行

sudo easy_install-2.7 pip

使用pip-2.7安装Wand

sudo pip-2.7 install Wand