首页 > Python编程 > python升级引起的pip执行错误

python升级引起的pip执行错误

2015年5月9日

python升级引起的pip执行错误
http://blog.csdn.net/iefreer/article/details/8086834
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 plaincopy
[[email protected] 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:
[[email protected] 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即可。

分类: Python编程 标签:
本文的评论功能被关闭了.