升级新版本python后,yum安装文件时会报错,原因在于yum是python编写,python版本不一致导致脚本运行错误所致,可以修改yum文件解决问题,需要的朋友参考下。
python升级后yum报错修复方法
升级python版本后,运行yum:
# yum -y install openssl
提示:
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.3 (default, Jul 15 2014, 16:52:36)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)]
If you cannot solve this problem yourself, please go to
the yum faq at:
http://wiki.linux.duke.edu/YumFaq
原因:yum和Python是依赖关系,yum是python的模块,需要修改yum解决此问题。
yum修复过程如下:
1、查看python的安装路径
# python
Python 2.7.3 (default, Jul 15 2014, 16:52:36)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
# whereis python
python: /usr/bin/python2.4 /usr/bin/python /usr/bin/python2.6 /usr/lib/python2.4 /usr/local/bin/python
/usr/local/bin/python2.6-config /usr/local/bin/python3.3-config /usr/local/bin/python3.3 /usr/local/bin/python3.3m
/usr/local/bin/python3.3m-config /usr/local/bin/python2.6 /usr/local/lib/python2.4 /usr/local/lib/python3.3
/usr/local/lib/python2.6 /usr/
include/python2.4 /usr/share/man/man1/python.1.gz
2、修改yum
# vim /usr/bin/yum
将 #!/usr/bin/python 改成 #!/usr/bin/python2.4
【保存并退出】
3、测试yum安装,成功;
附,python升级导致yum不可用的解决方法
在一台服务器上yum安装RRDTool,发现yum报错,不能使用。
登陆服务器检查,发现python被人从2.4升级到了2.6,,使用yum报错:ImportError: No module named rpm
显示yum的python脚本无法导入rpm包
手动修改/usr/bin/yum脚本头部
将#!/usr/bin/python改成#!/usr/bin/python2.4
附2,执行yum报错:Insufficient server config – no servers found. Aborting.
终极解决办法:
1、使用rpm将python2.6降级,注意rpm -e掉python2.6后,需要将/usr/bin/下的python和python2做个软件到/usr/bin/python2.4
2、重新安装yum:
rpm -ivh python-iniparse-0.2.3-4.el5.noarch.rpm
rpm -ivh yum-metadata-parser-1.1.2-3.el5.
centos.x86_64.rpm
rpm -ivh yum-fastestmirror-1.1.16-14.el5.centos.1.noarch.rpm yum-3.2.22-26.el5.centos.noarch.rpm
3、清理一些垃圾源
最终yum update成功。
附3,python升级导致yum命令无法使用的解决方案
操作过程:
[root@web-server ~]# 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.5.4 (r254:67916, Feb 24 2010, 10:03:49)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)]
If you cannot solve this problem yourself, please go to
the yum faq at:
http://wiki.linux.duke.edu/YumFaq
解决方法:
查找yum文件,并编辑此py文件
[root@web-server ~]# which yum
/usr/bin/yum
[root@web-server ~]# vi /usr/bin/yum
将
#!/usr/bin/python
改为:
#!/usr/bin/python2.4
保存文件,重启yum,再次执行成功。
另外的可能原因,无法使用yum,就是/usr/bin下的python、python2、python2.4三个文件一定不能改变。
yum只是基于python语言,跟版本并没有关系,但是升级过程中确实会出现问题,具体机制大家可以深入研究下。