合 yum安装报错“No module named yum”
Tags: 故障处理Linuxyumyum安装Python升级No module named yum重新安装yum
现象
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | [root@XT-Server80 yum.repos.d]# yum install -y wget 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 15 2020, 01:24:42) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] If you cannot solve this problem yourself, please go to the yum faq at: http://yum.baseurl.org/wiki/Faq [root@XT-Server80 yum.repos.d]# cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core) [root@XT-Server80 yum.repos.d]# python -V Python 2.7.12 [root@XT-Server80 Python-2.7.5]# python Python 2.7.12 (default, May 15 2020, 01:24:42) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] 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 >>> import sys >>> import yum Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named yum >>> |
故障分析
在CentOS 7上,yum依赖的Python版本为 2.7.5版本。在CentOS 6上,yum依赖的Python版本为 2.6.6版本。
原理:yum依赖于python,运行yum指令实际上是在python环境调用yum库运行后续指令;
报错原因:通常是安装了高版本的python替换了系统内置的,由于版本高,库没有,导致没法使用。
解决办法
1、若原来的Python版本还在,那么需要修改2个文件:vim /usr/bin/yum
和 vi /usr/libexec/urlgrabber-ext-down
将第一行代码#!/usr/bin/python
改成python原来的版本: #!/usr/bin/pythonXXX
这种情况只适用于你新装的python与yum原本依赖的python版本并存的情况下 才有效
2、若原来的python版本已经被覆盖了,那么就需要重新安装Python和yum包,步骤如下:
a、删除现有的python和yum
1 2 3 4 5 6 | rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps whereis python |xargs rm -frv -rf whereis python rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps whereis yum |xargs rm -frv -rf |
b、下载需要的包,包下载地址如下:http://mirrors.163.com/centos/7/os/x86_64/Packages/
我的环境是CentOS Linux release 7.6.1810 (Core)
,如下的包是7.3环境的,但是也可以用于7.6,下载的包如下所示: