报错:It‘s possible that the above module doesn‘t match the current version of Python, which is: 2.7.5
1、错误
因卸载python造成yum不可使用,后来再重新切换yum依赖的python版本,依然出现报错,如下:
[[email protected] bin]# 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.5 (default, Aug 17 2020, 17:30:24)
[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
在网上找了很多的方法,都没有成功,最后无奈之下,只能重新安装yum及其依赖的python。
2、Yum及其依赖的安装
1、清空python
rpm -qa|grep python|xargs rpm -e --allmatches --nodeps
whereis python|xargs rm -fr
xargs用法:管道实现的是将前面的stdout作为后面的stdin,但是有些命令不接受管道的传递方式,最常见的就是ls命令。有些时候命令希望管道传递的是参数,但是直接用管道有时无法传递到命令的参数位,这时候需要xargs,xargs实现的是将管道传输过来的stdin进行处理然后传递到命令的参数位上。也就是说xargs完成了两个行为:处理管道传输过来的stdin;将处理后的传递到正确的位置上。
rpm -qa <包名>: 查看安装的软件包
rpm -e <包名>:卸载安装包
–nodeps: 如果该RPM包的安装依赖其它包,即使其它包没装,也强迫安装
rpm -e --allmatches --nodeps <包的名字> :删除所有相同名字的包, 并忽略依赖,这里要删除的即rpm -qa|grep python查询的结果。
2、清空yum
rpm -qa|grep yum|xargs rpm -e --allmatches --nodeps
rm -rf /etc/yum.repos.d/*
whereis yum|xargs rm -fr
3、下载相应的RPM文件
下载地址:http://mirrors.163.com/centos/7/os/x86_64/Packages/
需要下载的文件有:
[[email protected] soft]# ls
python-2.7.5-88.el7.x86_64.rpm python-pycurl-7.19.0-19.el7.x86_64.rpm rpm-python-4.11.3-43.el7.x86_64.rpm
python2-rpm-macros-3-32.el7.noarch.rpm python-rpm-macros-3-32.el7.noarch.rpm yum-3.4.3-167.el7.centos.noarch.rpm
python-devel-2.7.5-88.el7.x86_64.rpm python-srpm-macros-3-32.el7.noarch.rpm yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
python-iniparse-0.4-9.el7.noarch.rpm python-urlgrabber-3.10-10.el7.noarch.rpm yum-plugin-fastestmirror-1.1.31-53.el7.noarch.rpm
python-libs-2.7.5-88.el7.x86_64.rpm rpm-4.11.3-43.el7.x86_64.rpm
4、python安装
rpm -ivh python-* rpm-*
5、安装yum
rpm -ivh yum-*
注意: 安装的过程,可能会出现依赖顺序的问题,按照提示先安装被依赖的软件即可。
6、验证yum命令
验证yum命令时,出现如下提示,说明yum安装成功了,但是需要配置下载源文件。
[[email protected] soft]# yum install vim
找不到配置文件 /etc/yum/pluginconf.d/product-id.conf
找不到插件 product-id 的配置文件
找不到配置文件 /etc/yum/pluginconf.d/search-disabled-repos.conf
找不到插件 search-disabled-repos 的配置文件
找不到配置文件 /etc/yum/pluginconf.d/subscription-manager.conf
找不到插件 subscription-manager 的配置文件
已加载插件:fastestmirror
Determining fastest mirrors
There are no enabled repos.
Run "yum repolist all" to see the repos you have.
To enable Red Hat Subscription Management repositories:
subscription-manager repos --enable <repo>
To enable custom repositories:
yum-config-manager --enable <repo>
首先执行如下命令,下载默认的镜像源:
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache
yum -y update
3、其他
安装rpm-4.11.3-43.el7.x86_64出现如下提醒,说明有冲突,安装失败(其他安装失败,处理方式一样)。
[[email protected] soft]# rpm -ivh python-urlgrabber-3.10-10.el7.noarch.rpm
准备中... ################################# [100%]
file /bin/rpm from install of rpm-4.11.3-43.el7.x86_64 conflicts with file from package rpm-4.11.3-35.el7.x86_64
file /usr/bin/rpm2cpio from install of rpm-4.11.3-43.el7.x86_64 conflicts with file from package rpm-4.11.3-35.el7.x86_64
file /usr/bin/rpmdb from install of rpm-4.11.3-43.el7.x86_64 conflicts with file from package rpm-4.11.3-35.el7.x86_64
file /usr/bin/rpmkeys from install of rpm-4.11.3-43.el7.x86_64 conflicts with file from package rpm-4.11.3-35.el7.x86_64
file /usr/lib/rpm/rpmpopt-4.11.3 from install of rpm-4.11.3-43.el7.x86_64 conflicts with file from package rpm-4.11.3-35.el7.x86_64
[[email protected] soft]#
重新上面提醒,说明软件冲突,安装时,添加–replacefiles参数即可。
rpm -ivh rpm-4.11.3-43.el7.x86_64.rpm --replacefiles