使用yum安装软件时报错: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.12 (default, May 5 2017, 16:25:06)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]

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

有点纳闷,机器近段时间没有异常操作。

错误原因:

yum命令不兼容python2.7
但是我的python2.7早就编译安装好的,查看了history,发现上个月更新了一个软件,期间升级了一些python包,但是系统未重启,今天重启过系统。

解决方法:

修改/usr/bin/yum文件,将第一行由“#!/usr/bin/python”改为“#!/usr/bin/python2.6”即可

sed -i '[email protected]^#!/usr/bin/[email protected]#!/usr/bin/[email protected]' /usr/bin/yum

使用yum安装软件时报错:No module named yum