首先介绍一下,win7 升级pip本身失败这个问题是来源于win7系统安装python包工具pip时失败,而下文介绍的则是基于python安装pip的正确步骤,所以并非答非所问。这以步骤适用于xp、win7、win8以及win10系统。而python包工具pip安装失败与使用哪个系统并没有任何关系。
centos5.x默认安装的python为2.4版本,但是部分软件需要2.5以上的python.
所以我们需要升级Python,比如到2.7版本,步骤
curl -O http://python.org/ftp/python/2.7/Python-2.7.tgz
tar xfz Python-2.7.tgz
cd Python-2.7
./configure
make && make install
把/usr/bin/python更换为python2.7的软链接
ln -s /usr/local/bin/python2.7.3 /usr/bin/python
用python -V确认一下版本。
但问题是把python升级后,原先安装的pip运行可能会遇到错误,如下:
[plain] view plain copy
[root@dev1 bin]# pip
Traceback (most recent call last):
File "/usr/bin/pip", line 7, in ?
sys.exit(
File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 236, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 2097, in load_entry_point
return ep.load()
File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 1830, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/usr/lib/python2.4/site-packages/pip-1.2.1-py2.4.egg/pip/__init__.py", line 9, in ?
from pip.basecommand import command_dict, load_command, load_all_commands, command_names
File "/usr/lib/python2.4/site-packages/pip-1.2.1-py2.4.egg/pip/basecommand.py", line 4, in ?
from pkgutil import walk_packages
ImportError: cannot import name walk_packages
所以pip也需要升级到配套的版本:
curl -O http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg
sh setuptools-0.6c11-py2.7.egg
easy_install pip
现在再查看/usr/local/bin目录下面的pip:
[root@dev1 bin]# ll /usr/local/bin |grep pip
-rwxr-xr-x 1 root root 250 Oct 18 17:23 pip
-rwxr-xr-x 1 root root 258 Oct 18 17:23 pip-2.7
用pip-2.7即可。