Centos7.8误删python2.7恢复方法(亲测)

Centos7.8误删python2.7恢复方法

在下载新版本或者更新python版本时,一定不要删除系统自带的python版本!不然会带来很多麻烦,包括yum、pip等命令不能用的情况,这时需要修改相应py文件头的环境变量,会变得相当麻烦。

1、删除python环境(慎重)

# 卸载老板版的Python
[root@centos04 ~]# rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps   ##强制删除已安装程序及其关联
[root@centos04 ~]# whereis python |xargs rm -frv     ##删除所有残余文件 xargs,允许你对输出执行其他某些命令
[root@centos04 ~]# whereis python                    ##验证删除,返回无结果

2、查看自己centos系统版本

[root@centos04 ~]# cat /etc/redhat-release
CentOS Linux release 7.8.2003 (Core)

3.使用wget分别下载python以及yum的rpm包

地址:http://vault.centos.org/

我的版本是7.8.2003,下载地址为:https://vault.centos.org/7.8.2003/os/x86_64/Packages/

注意:你需要查看自己版本,然后进入相应版本的目录下,下载rpm包

比如,你的centos版本是7.6.1810,那么你的下载地址为:wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/python-2.7.5-76.el7.x86_64.rpm,而我的版本是:wget http://vault.centos.org/7.8.2003/os/x86_64/Packages/python-2.7.5-88.el7.x86_64.rpm目录不一样,rpm包的包名也可能不一样。

[root@centos04 ~]# mkdir /usr/local/src/python
[root@centos04 ~]# cd /usr/local/src/python

我的版本需要下载的文件及目录如下(注意,你需要自己去目录下搜索rpm包名,否则有的包找不到):

wget http://vault.centos.org/7.8.2003/os/x86_64/Packages/python-backports-1.0-8.el7.x86_64.rpm
wget http://vault.centos.org/7.8.2003/os/x86_64/Packages/python-2.7.5-88.el7.x86_64.rpm
wget http://vault.centos.org/7.8.2003/os/x86_64/Packages/libxml2-python-2.9.1-6.el7.4.x86_64.rpm
wget http://vault.centos.org/7.8.2003/os/x86_64/Packages/python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch.rpm
wget http://vault.centos.org/7.8.2003/os/x86_64/Packages/python-chardet-2.2.1-3.el7.noarch.rpm
wget http://vault.centos.org/7.8.2003/os/x86_64/Packages/python-devel-2.7.5-88.el7.x86_64.rpm
wget http://vault.centos.org/7.8.2003/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
wget http://vault.centos.org/7.8.2003/os/x86_64/Packages/python-ipaddress-1.0.16-2.el7.noarch.rpm
wget http://vault.centos.org/7.8.2003/os/x86_64/Packages/python-kitchen-1.1.1-5.el7.noarch.rpm
wget http://vault.centos.org/7.8.2003/os/x86_64/Packages/python-libs-2.7.5-88.el7.x86_64.rpm
wget http://vault.centos.org/7.8.2003/os/x86_64/Packages/python-pycurl-7.19.0-19.el7.x86_64.rpm
wget http://vault.centos.org/7.8.2003/os/x86_64/Packages/python-setuptools-0.9.8-7.el7.noarch.rpm
wget http://vault.centos.org/7.8.2003/os/x86_64/Packages/python-urlgrabber-3.10-10.el7.noarch.rpm
wget http://vault.centos.org/7.8.2003/os/x86_64/Packages/python-virtualenv-15.1.0-2.el7.noarch.rpm
wget http://vault.centos.org/7.8.2003/os/x86_64/Packages/rpm-4.11.3-43.el7.x86_64.rpm
wget http://vault.centos.org/7.8.2003/os/x86_64/Packages/rpm-build-4.11.3-43.el7.x86_64.rpm
wget http://vault.centos.org/7.8.2003/os/x86_64/Packages/rpm-build-libs-4.11.3-43.el7.x86_64.rpm
wget http://vault.centos.org/7.8.2003/os/x86_64/Packages/rpm-libs-4.11.3-43.el7.x86_64.rpm
wget http://vault.centos.org/7.8.2003/os/x86_64/Packages/rpm-python-4.11.3-43.el7.x86_64.rpm
wget http://vault.centos.org/7.8.2003/os/x86_64/Packages/rpm-sign-4.11.3-43.el7.x86_64.rpm
wget http://vault.centos.org/7.8.2003/os/x86_64/Packages/yum-3.4.3-167.el7.centos.noarch.rpm
wget http://vault.centos.org/7.8.2003/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://vault.centos.org/7.8.2003/os/x86_64/Packages/yum-plugin-aliases-1.1.31-53.el7.noarch.rpm
wget http://vault.centos.org/7.8.2003/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-53.el7.noarch.rpm
wget http://vault.centos.org/7.8.2003/os/x86_64/Packages/yum-plugin-protectbase-1.1.31-53.el7.noarch.rpm
wget http://vault.centos.org/7.8.2003/os/x86_64/Packages/yum-utils-1.1.31-53.el7.noarch.rpm
[root@centos04 python]# ll
total 12840
-rw-r--r--. 1 root root  252824 Apr  4  2020 libxml2-python-2.9.1-6.el7.4.x86_64.rpm
-rw-r--r--. 1 root root   97976 Apr  4  2020 python-2.7.5-88.el7.x86_64.rpm
-rw-r--r--. 1 root root    5932 Mar 14  2015 python-backports-1.0-8.el7.x86_64.rpm
-rw-r--r--. 1 root root   12896 Apr 25  2018 python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch.rpm
-rw-r--r--. 1 root root  232448 Aug 23  2019 python-chardet-2.2.1-3.el7.noarch.rpm
-rw-r--r--. 1 root root  407848 Apr  4  2020 python-devel-2.7.5-88.el7.x86_64.rpm
-rw-r--r--. 1 root root   39800 Jul  4  2014 python-iniparse-0.4-9.el7.noarch.rpm
-rw-r--r--. 1 root root   35176 Nov 21  2016 python-ipaddress-1.0.16-2.el7.noarch.rpm
-rw-r--r--. 1 root root  273012 Jul  4  2014 python-kitchen-1.1.1-5.el7.noarch.rpm
-rw-r--r--. 1 root root 5918924 Apr  4  2020 python-libs-2.7.5-88.el7.x86_64.rpm
-rw-r--r--. 1 root root   82396 Nov 21  2016 python-pycurl-7.19.0-19.el7.x86_64.rpm
-rw-r--r--. 1 root root  406404 Aug 11  2017 python-setuptools-0.9.8-7.el7.noarch.rpm
-rw-r--r--. 1 root root  111048 Apr  4  2020 python-urlgrabber-3.10-10.el7.noarch.rpm
-rw-r--r--. 1 root root 1771300 Apr 25  2018 python-virtualenv-15.1.0-2.el7.noarch.rpm
-rw-r--r--. 1 root root 1219660 Apr  4  2020 rpm-4.11.3-43.el7.x86_64.rpm
-rw-r--r--. 1 root root  152832 Apr  4  2020 rpm-build-4.11.3-43.el7.x86_64.rpm
-rw-r--r--. 1 root root  109752 Apr  4  2020 rpm-build-libs-4.11.3-43.el7.x86_64.rpm
-rw-r--r--. 1 root root  284848 Apr  4  2020 rpm-libs-4.11.3-43.el7.x86_64.rpm
-rw-r--r--. 1 root root   85760 Apr  4  2020 rpm-python-4.11.3-43.el7.x86_64.rpm
-rw-r--r--. 1 root root   49800 Apr  4  2020 rpm-sign-4.11.3-43.el7.x86_64.rpm
-rw-r--r--. 1 root root 1298672 Apr  4  2020 yum-3.4.3-167.el7.centos.noarch.rpm
-rw-r--r--. 1 root root   28348 Jul  4  2014 yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
-rw-r--r--. 1 root root   32016 Apr  4  2020 yum-plugin-aliases-1.1.31-53.el7.noarch.rpm
-rw-r--r--. 1 root root   35004 Apr  4  2020 yum-plugin-fastestmirror-1.1.31-53.el7.noarch.rpm
-rw-r--r--. 1 root root   27824 Apr  4  2020 yum-plugin-protectbase-1.1.31-53.el7.noarch.rpm
-rw-r--r--. 1 root root  124628 Apr  4  2020 yum-utils-1.1.31-53.el7.noarch.rpm

4、安装

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

5、测试是否可用

[root@centos04 python]# python -V
Python 2.7.5

你可能感兴趣的:(linux,python,linux,centos)