1.系统环境:
# uname -a
Linux swarm-worker1 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
2.问题描述:
因需要将python版本更新到2.7.9,编译安装新版本时忽略了yum与python的关系(yum是由python编写的),直接将现有的python(版本号:2.7.5)删除了,导致yum无法使用,报如下错误:
此时python可以正常使用:
3.解决办法:
尝试一:卸载新版本python,装回老版本:
#whereis python | xargs rm -rf
#tar -zxvf Python-2.7.5.tgz
#./configure --prefix=/usr
#make
#make install
此时,python版本恢复到2.7.5,且可以使用,但yum仍无法使用。尝试更改yum文件仍无效:
# cat /usr/bin/yum
#!/usr/bin/python
失败原因分析:
与python相关的组件没有清理干净。
尝试二:卸载python,手动安装所有组件
#rpm -qa | grep python | xargs rpm -e --allmatches --nodeps
#whereis python | xargs rm -rf
# rpm -qa | grep python // 此时已没有与python相关的组件
#mkdir python-rpm // 创建python的rpm包的存放目录
从官网下载相应的python组件,相关组件目录通过百度搜索得知:
#wget https://vault.centos.org/7.4.1708/os/x86_64/Packages/lvm2-python-libs-2.02.171-8.el7.x86_64.rpm
#wget https://vault.centos.org/7.4.1708/os/x86_64/Packages/libxml2-python-2.9.1-6.el7_2.3.x86_64.rpm
#wget https://vault.centos.org/7.4.1708/os/x86_64/Packages/python-libs-2.7.5-58.el7.x86_64.rpm
#wget https://vault.centos.org/7.4.1708/os/x86_64/Packages/python-ipaddress-1.0.16-2.el7.noarch.rpm
#wget https://vault.centos.org/7.4.1708/os/x86_64/Packages/python-backports-1.0-8.el7.x86_64.rpm
#wget https://vault.centos.org/7.4.1708/os/x86_64/Packages/python-backports-ssl_match_hostname-3.4.0.2- 4.el7.noarch.rpm
#wget https://vault.centos.org/7.4.1708/os/x86_64/Packages/python-2.7.5-58.el7.x86_64.rpm
#wget https://vault.centos.org/7.4.1708/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
#wget https://vault.centos.org/7.4.1708/os/x86_64/Packages/python-pycurl-7.19.0-19.el7.x86_64.rpm
#wget https://vault.centos.org/7.4.1708/os/x86_64/Packages/python-urlgrabber-3.10-8.el7.noarch.rpm
#wget https://vault.centos.org/7.4.1708/os/x86_64/Packages/python-setuptools-0.9.8-7.el7.noarch.rpm
#wget https://vault.centos.org/7.4.1708/os/x86_64/Packages/python-kitchen-1.1.1-5.el7.noarch.rpm
#wget https://vault.centos.org/7.4.1708/os/x86_64/Packages/python-chardet-2.2.1-1.el7_1.noarch.rpm
#wget https://vault.centos.org/7.4.1708/os/x86_64/Packages/rpm-python-4.11.3-25.el7.x86_64.rpm
#wget https://vault.centos.org/7.4.1708/os/x86_64/Packages/yum-utils-1.1.31-42.el7.noarch.rpm
#wget https://vault.centos.org/7.4.1708/os/x86_64/Packages/yum-3.4.3-154.el7.centos.noarch.rpm
#wget https://vault.centos.org/7.4.1708/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
#wget https://vault.centos.org/7.4.1708/os/x86_64/Packages/yum-plugin-aliases-1.1.31-42.el7.noarch.rpm
#wget https://vault.centos.org/7.4.1708/os/x86_64/Packages/yum-plugin-protectbase-1.1.31-42.el7.noarch.rpm
#wget https://vault.centos.org/7.4.1708/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-42.el7.noarch.rpm
安装rpm包:
#rpm -Uvh --replacepkgs python*.rpm
#rpm -Uvh --replacepkgs lvm2-python-libs*.rpm --nodeps --force
#rpm -Uvh --replacepkgs libxml2-python*.rpm
#rpm -Uvh --replacepkgs rpm-python*.rpm yum*.rpm --nodeps --force
至此,问题解决。
扩展:
以上rpm包如果不能确定,可以挂载同版本的系统光盘,然后在Packages目录下执行相关rpm包安装命令。
此方法没有实行,待验证。
#mount -t iso9660 /dev/sr0 /media/cdrom