No module named yum 报错

Posted mingetty

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了No module named yum 报错相关的知识,希望对你有一定的参考价值。

今天在测试服务器用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.7.6 (default, Sep 29 2018, 18:12:27)
[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

技术图片

这是因为升级python后, 没有指定yum用系统自带python版本导致的. yum和Python有依赖关系,yum是python的模块. 

[[email protected] ~]# python -V     # 果然是有人升级版本了, centos 6 默认是2.6的
Python 2.7.6
[[email protected]-A ~]# which python
/usr/local/bin/python
[[email protected]-A ~]# ll /usr/local/bin/python
lrwxrwxrwx 1 root root 7 Sep 29 18:13 /usr/local/bin/python -> python2
[[email protected]-A ~]# ll /usr/local/bin/python2
lrwxrwxrwx 1 root root 9 Sep 29 18:13 /usr/local/bin/python2 -> python2.7
[[email protected]-A ~]# which python2.6
/usr/bin/python2.6
[[email protected]-A ~]# 
[[email protected] ~]# vim /usr/bin/yum  ###修改这个文件, 把第一行 #!/usr/bin/python 改为 #!/usr/bin/python2.6
#!/usr/bin/python2.6

看这样就好了, 升级Python我之前也写过, 可以参考一下

技术图片

 

以上是关于No module named yum 报错的主要内容,如果未能解决你的问题,请参考以下文章

CentOS6.5运行yum报错:No module named yum

Linux—运行yum报错:No module named yum

CentOS 6.* 运行yum报错:No module named rpm

centos 系统服务器yum源报错 “No module named yum”

yum执行报错No module named yummain处理

import yum ImportError: No module named yum