[故障]Python 版本问题 + Yum 无法正常使用,提示 No module named yum
原因
记:执行安装某个程序时将云服务器Python
默认版本替换导致yum
无法使用问题,并且是最坏的情况,把Python
和 yum
都删了,下面是参考的文献和解决方案
参考文献:
1、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, Oct 14 2020, 14:45:30)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
If you cannot solve this problem yourself, please go to
the yum faq at:
http://yum.baseurl.org/wiki/Faq
2、将原有Python
和yum
全部删除
2.1 删除Python
#删除现有的python
[root@test ~]# rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps ##强制删除已安装程序及其关联
[root@test ~]# whereis python |xargs rm -frv ##删除所有残余文件 ##xargs,允许你对输出执行其他某些命令
[root@test ~]# whereis python ##验证删除,返回无结果
2.2 删除yum
#删除现有的yum
[root@test ~]# rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps
[root@test ~]# whereis yum |xargs rm -frv
2.3 从阿里云镜像下载相对应的包
根据自己的系统版本去找对应Packages
如果不知道自己的系统版本,命令行输入这个cat /etc/redhat-release
阿里云镜像 developer.aliyun.com/mirror/?spm=a...
我这边使用的是CentOS7
所以找对应的7版本就可以了
2.4 下载Python
依赖的rpm
包
下面是所有需要使用到的包:
需要用到的包
python-2.7.5-89.el7.x86_64.rpm
python-devel-2.7.5-89.el7.x86_64.rpm
python-iniparse-0.4-9.el7.noarch.rpm
python-kitchen-1.1.1-5.el7.noarch.rpm
python-libs-2.7.5-89.el7.x86_64.rpm
python-pycurl-7.19.0-19.el7.x86_64.rpm
python-setuptools-0.9.8-7.el7.noarch.rpm
python-urlgrabber-3.10-10.el7.noarch.rpm
rpm-python-4.11.3-45.el7.x86_64.rpm
将所有需要下载的链接放到一个txt文件中进行批量下载
https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-libs-2.7.5-89.el7.x86_64.rpm
https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-2.7.5-89.el7.x86_64.rpm
https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-pycurl-7.19.0-19.el7.x86_64.rpm
https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-urlgrabber-3.10-10.el7.noarch.rpm
https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/rpm-python-4.11.3-45.el7.x86_64.rpm
https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-devel-2.7.5-89.el7.x86_64.rpm
https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-kitchen-1.1.1-5.el7.noarch.rpm
https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-setuptools-0.9.8-7.el7.noarch.rpm
执行下载,并强制安装
[root@test ~]# wget -i python-rpm.txt
[root@test ~]# rpm -Uvh python-libs-2.7.5-89.el7.x86_64.rpm --nodeps
[root@test ~]# rpm -Uvh python-2.7.5-89.el7.x86_64.rpm --nodeps
[root@test ~]# rpm -Uvh python-iniparse-0.4-9.el7.noarch.rpm --nodeps
[root@test ~]# rpm -Uvh python-pycurl-7.19.0-19.el7.x86_64rpm --nodeps
[root@test ~]# rpm -Uvh python-urlgrabber-3.10-10.el7.noarch.rpm --nodepsls
[root@test ~]# rpm -Uvh rpm-python-4.11.3-45.el7.x86_64.rpm --nodeps
[root@test ~]# rpm -Uvh python-devel-2.7.5-89.el7.x86_64.rpm --nodeps
[root@test ~]# rpm -Uvh python-kitchen-1.1.1-5.el7.noarch.rpm --nodeps
[root@test ~]# rpm -Uvh python-setuptools-0.9.8-7.el7.noarch.rpm --nodeps
2.5 下载yum
依赖的rpm
包
https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-3.4.3-168.el7.centos.noarch.rpm
https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm
https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-plugin-aliases-1.1.31-54.el7_8.noarch.rpm
https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-plugin-protectbase-1.1.31-54.el7_8.noarch.rpm
https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-updateonboot-1.1.31-54.el7_8.noarch.rpm
https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-54.el7_8.noarch.rpm
https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
[root@test ~]# mkdir -p yum-rpm/
[root@test ~]# cd yum-rpm/
[root@test ~]# wget -i yum-rpm.txt
[root@test ~]# rpm -Uvh *.rpm --nodeps
3、链接新的Python
命令
[root@test ~]# ln -fs /usr/bin/python2 /usr/bin/python
4、测试yum
[root@test ~]# yum
本作品采用《CC 协议》,转载必须注明作者和本文链接