【Python基础系列】centos7下Python2.7.5重新安装

业务背景

都快2023年了,还有2.7.5版本的Python存在,不能忍。想着卸载干净。

结果不到十分钟就被打脸了。

卸载python2.7.5的命令

rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps
whereis python|xargs rm -frv

结果在安装python3的时候,提示语法出错,原来yum命令是基于python实现的(心中万马奔腾)。
没有办法,只能去恢复了。不过恢复也很快。

python 2.7.5 恢复过程

centos版本

cat /etc/redhat-release

知道了自己的版本号。

去vault.centos.org下载rpm包

下载如下的包:

命令如下:

wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/libxml2-python-2.9.1-6.el7_2.3.x86_64.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/python-chardet-2.2.1-1.el7_1.noarch.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/python-devel-2.7.5-76.el7.x86_64.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/python-ipaddress-1.0.16-2.el7.noarch.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/python-kitchen-1.1.1-5.el7.noarch.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/python-libs-2.7.5-76.el7.x86_64.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/python-pycurl-7.19.0-19.el7.x86_64.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/python-setuptools-0.9.8-7.el7.noarch.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/python-urlgrabber-3.10-9.el7.noarch.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/python-virtualenv-15.1.0-2.el7.noarch.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/rpm-4.11.3-35.el7.x86_64.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/rpm-build-4.11.3-35.el7.x86_64.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/rpm-build-libs-4.11.3-35.el7.x86_64.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/rpm-libs-4.11.3-35.el7.x86_64.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/rpm-python-4.11.3-35.el7.x86_64.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/rpm-sign-4.11.3-35.el7.x86_64.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/yum-3.4.3-161.el7.centos.noarch.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/yum-plugin-aliases-1.1.31-50.el7.noarch.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-50.el7.noarch.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/yum-plugin-protectbase-1.1.31-50.el7.noarch.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/yum-utils-1.1.31-50.el7.noarch.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/lvm2-python-libs-2.02.180-8.el7.x86_64.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

验证过程

输入:

python -V