No module named yum解决

在机器中分别装了2个比系统默认版本高的python后,再次使用yum的时候发现报错了,如下:

[root@localhost ~]# 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.8 (unknown, Jun 18 2015, 16:07:56) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)]

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

yum是用python实现的,应该是默认执行时用了不匹配的版本,将yum中的python版本改到能import yum模块的即可。

  • 查看系统中有哪些python
    [root@localhost ~]# whereis python
    python: /usr/bin/python2.6-config /usr/bin/python /usr/bin/python2.6 /usr/lib/python2.6 /usr/lib64/python2.6 /usr/local/bin/python2.6-config /usr/local/bin/python /usr/local/bin/python2.7-config /usr/local/bin/python2.7 /usr/local/bin/python2.6 /usr/local/lib/python2.7 /usr/local/lib/python2.6 /usr/include/python2.6 /usr/share/man/man1/python.1.gz
    
  • 先测试2.6的
    [root@localhost ~]# /usr/bin/python2.6
    Python 2.6.6 (r266:84292, Nov 22 2013, 12:16:22) 
    [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import yum
    >>> exit()
    

    再测试默认2.7.10的

    [root@localhost ~]# python
    Python 2.7.10 (default, Jun 18 2015, 15:51:08) 
    [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import yum
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    ImportError: No module named yum
    >>> exit()
    
  • 修改yum的默认python版本
    [root@localhost ~]# vim /usr/bin/yum
    #!/usr/bin/python2.6
    原文作者:netxfly
    原文地址: https://zhuanlan.zhihu.com/p/20078630
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞