linux系统中yum报错的解决方法

linux系统中运行yum报错

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.6.6 (r266:84292, Dec  2 2016, 14:46:54) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)]

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

根据错误提示来看应该是因为yum和python版本不兼容引起的,以下以centos6.5为例
centos6.5中python版本为2.6.6,yum版本为3.2.29,当python版本被升级后就会导致yum报错
针对这种情况有以下几种解决方法:

  1. 修改yum脚本
    编辑/usr/bin/yum

    # vim /usr/bin/yum
    

    #!/usr/bin/python修改为 #!/usr/bin/python2.6.6

  2. /usr/bin/python2.6.6软连接到/usr/bin/python

    # ln -s /usr/bin/python2.6.6 /usr/bin/python
    
  3. 将yum升级到与python版本匹配的版本

36nu 分享编程知识及经验

已有账号?立即登录