yum 报错解决( No module named yum)
服务器是centos 5.9 64位的系统,因为好几个人一起用,不清楚其它人做了什么。
任何yum操作都会报错,错误信息如下:
[root@LB1603 log]# yum --version
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 (r27:82500, Sep 9 2014, 04:09:22)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)]
If you cannot solve this problem yourself, please go to
the yum faq at:
http://wiki.linux.duke.edu/YumFaq
错误原因:在yum 的faq中提到,yum是python的一个模块,如果yum所依赖的python版本不一致,就会出现这个问题。
先看一下python的版本:
[root@LB1603 log]# whereis python
python: /usr/bin/python /usr/bin/python.bak /usr/bin/python2.4 /usr/lib/python2.4 /usr/local/bin/python2.7 /usr/local/bin/python2.7-config /usr/local/bin/python /usr/local/lib/python2.7 /usr/include/python2.4 /usr/share/man/man1/python.1.gz
有两个版本,分别试着导入一下yum包:
root@LB1603 log]# python
Python 2.7 (r27:82500, Sep 9 2014, 04:09:22)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] 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
提示 No module named yum 和直接运行yum的报错一致,换个版本试下:
[root@LB1603 log]# python2.4
Python 2.4.3 (#1, Jan 9 2013, 06:47:03)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import yum
成功导入了,原因找到了,解决方法很简单:
vim /usr/bin/yum
把开头 #!/usr/bin/python 改为 #!/usr/bin/python2.4 保存退出即可。
在python的路径中看到有一个/usr/bin/python.bak的备份文件,看下了下版本是python2.4,基本上可以肯定是有人升级了python,导致了这个问题
参考文章:
http://blog.csdn.net/ei__nino/article/details/8495295
http://yum.baseurl.org/wiki/Faq
[...]yum 报错解决( No module named yum)[...]