CentOS 7 升级Python到2.7.11后yum无法使用,提示下面信息
# yum updateLoaded plugins: fastestmirrorLoading mirror speeds from cached hostfile * base: mirrors.aliyuncs.com * epel: mirrors.aliyuncs.com * extras: mirrors.aliyuncs.com * updates: mirrors.aliyuncs.comTraceback (most recent call last): File "/usr/libexec/urlgrabber-ext-down", line 22, in <module> from urlgrabber.grabber import /ImportError: No module named urlgrabber.grabberTraceback (most recent call last): File "/usr/libexec/urlgrabber-ext-down", line 22, in <module> from urlgrabber.grabber import /ImportError: No module named urlgrabber.grabber
解决办法,修改2个地方
vi /usr/bin/yum
修改第一行 #!/usr/bin/python
为 #!
/usr/bin/python2
.7
然后呢
vi /usr/libexec/urlgrabber-ext-down
把头部的python改成和/usr/bin/yum中一样的
这里顺便说一下如何升级,centos7默认Python是2.7.5
第一步:下载软件包
wget https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz
第二步:解包编译
tar zxvf Python-2.7.11.tgz cd Python-2.7.11
在编译前先在/usr/local下建立一个文件夹python2 ( 这个是Python的默认安装路径,取个别的名字以免覆盖老版本)
# mkdir /usr/local/python2
开始编译
# ./configure --prefix=/usr/local/python2 # make # make install
移走以前的版本
# mv /usr/bin/python /usr/bin/python_old
创建新的链接
ln -s /usr/local/python2/bin/python /usr/bin/python
现在直接输入python即可查看版本
# python Python 2.7.11 (default, Feb 19 2016, 18:01:00) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>
完成,这个时候yum 会使用不了,安装上面的执行就可以解决这个问题!!