Cent OS 7.6.1810重新安装Python 2.7和yum
由于Cent OS7自带的python大多数是2.7版本,当装python3的版本于是把原本自带的yum一起给卸载了
# 如果指定为python3 写为python, yum也就卸载了
rpm -qa|grep python3|xargs rpm -ev --allmatches --nodeps # 卸载python3,带2卸载python2,啥都不带会卸载所有python
whereis python3 |xargs rm -frv # 清除Python3残余文件
后来重新安装python2,python2可用,但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:
If you cannot solve this problem yourself, please go to the yum faq at:
http://wiki.linux.duke.edu/YumFaq
一、删除Cent OS自带的Python版本
强制删除已安装python及其关联
rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps
删除残留文件
whereis python|xargs rm -frv
二、重新安装python2.7和yum
- 查看当前cent os版本
[root@node45 ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
-
从镜像站下载所需的rpm文件
# 由于7.6.1810已经过时,需要在http://vault.centos.org/下载pack wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/lvm2-python-libs-2.02.180-8.el7.x86_64.rpm wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/libxml2-python-2.9.1-6.el7_2.3.x86_64.rpm wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/python-libs-2.7.5-76.el7.x86_64.rpm wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/python-ipaddress-1.0.16-2.el7.noarch.rpm wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/python-backports-1.0-8.el7.x86_64.rpm wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch.rpm wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/python-2.7.5-76.el7.x86_64.rpm wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/python-pycurl-7.19.0-19.el7.x86_64.rpm wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/python-urlgrabber-3.10-9.el7.noarch.rpm wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/python-setuptools-0.9.8-7.el7.noarch.rpm wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/python-kitchen-1.1.1-5.el7.noarch.rpm wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/python-chardet-2.2.1-1.el7_1.noarch.rpm wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/rpm-python-4.11.3-35.el7.x86_64.rpm wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/yum-utils-1.1.31-50.el7.noarch.rpm wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/yum-3.4.3-161.el7.centos.noarch.rpm wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/yum-plugin-aliases-1.1.31-50.el7.noarch.rpm wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/yum-plugin-protectbase-1.1.31-50.el7.noarch.rpm
-
在当前文件夹下执行以下安装命令
rpm -Uvh --replacepkgs lvm2-python-libs*.rpm --nodeps --force rpm -Uvh --replacepkgs libxml2-python*.rpm --nodeps --force rpm -Uvh --replacepkgs python*.rpm --nodeps --force rpm -Uvh --replacepkgs rpm-python*.rpm yum*.rpm --nodeps --force
-
验证,大功告成。