念念不忘
必有回响

CentOS升级Python27后,yum不可用

之前一篇文章介绍了《Centos6.8升级Python2.6为Python2.7》,升级完毕后通过pip安装依赖时不再提示版本过期,但是随之而来的问题就是yum不好使了,例如会出现如下报错

[root@tvzr ~]# yum search jpegoptim 
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:

   No module named yum

Please install a package which provides this module, or
verify that the module is installed correctly.

It's possible that the above module doesn't match the
current version of Python, which is:
2.7.13 (default, May 15 2017, 11:00:16) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)]

If you cannot solve this problem yourself, please go to 
the yum faq at:
  http://yum.baseurl.org/wiki/Faq

问题原因是因为yum不支持python2.7的版本,那么只需要在/usr/bin/yum中将第一行的#!/usr/bin/python更换为低版本即可。

vim /usr/bin/yum

原来的头部声明

#!/usr/bin/python

更换以后的头部声明

#!/usr/bin/python2.6

这个python2.6怎么来的呢?

ll /usr/bin/py*

这里就会看到系统自带的以及我们升级后的python

[root@tvzr ~]# ll /usr/bin/py*
-rwxr-xr-x 1 root root   78 Aug 18  2016 /usr/bin/pydoc
lrwxrwxrwx 1 root root   34 May 15 11:03 /usr/bin/python -> /usr/local/python2.7/bin/python2.7
lrwxrwxrwx 1 root root    6 Apr 16 23:02 /usr/bin/python2 -> python
-rwxr-xr-x 2 root root 4864 Aug 18  2016 /usr/bin/python2.6
lrwxrwxrwx 1 root root   34 May 15 11:09 /usr/bin/python2.7 -> /usr/local/python2.7/bin/python2.7
-rwxr-xr-x 2 root root 4864 Aug 18  2016 /usr/bin/python_old  

按下esc,并且键入:wq即可保存修改。那么现在yum包管理器就好使了:

[root@tvzr ~]# yum search jpegoptim
Loaded plugins: fastestmirror
Repository epel is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                                                                                                                                             | 3.7 kB     00:00     
epel                                                                                                                                                                                                             | 4.3 kB     00:00     
epel/primary_db                                                                                                                                                                                                  | 5.9 MB     00:05     
extras                                                                                                                                                                                                           | 3.4 kB     00:00     
updates                                                                                                                                                                                                          | 3.4 kB     00:00     
======================================================================================================== N/S Matched: jpegoptim ========================================================================================================
jpegoptim.x86_64 : Utility to optimize JPEG files

  Name and summary matches only, use "search all" for everything.
赞(0) 打赏
未经允许不得转载:码农志 » CentOS升级Python27后,yum不可用
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏