CentOS7重新安装python、yum报错 /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or director

通京
2023-12-01

1、删除现有Python

rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps ##强制删除已安装程序及其关联
whereis python |xargs rm -frv -rf ##删除所有残余文件 ##xargs,允许你对输出执行其他某些命令
 whereis python ##验证删除,返回无结果

2、删除现有的yum

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

3、从http://mirrors.163.com/centos/7/os/x86_64/Packages/下相应的包

==由于源中版本会更新,下载时具体请查看版本再下载下来! ==

此版本使用时间 2019年6月

python-2.7.5-76.el7.x86_64.rpm
python-devel-2.7.5-76.el7.x86_64.rpm
python-iniparse-0.4-9.el7.noarch.rpm
python-libs-2.7.5-76.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-9.el7.noarch.rpm
rpm-python-4.11.3-35.el7.x86_64.rpm
yum-3.4.3-161.el7.centos.noarch.rpm
yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
yum-plugin-aliases-1.1.31-50.el7.noarch.rpm
yum-plugin-fastestmirror-1.1.31-50.el7.noarch.rpm
yum-plugin-protectbase-1.1.31-50.el7.noarch.rpm
yum-utils-1.1.31-50.el7.noarch.rpm

wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-2.7.5-76.el7.x86_64.rpm 
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-devel-2.7.5-76.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm 
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-libs-2.7.5-76.el7.x86_64.rpm 
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-pycurl-7.19.0-19.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-setuptools-0.9.8-7.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-urlgrabber-3.10-9.el7.noarch.rpm  
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/rpm-python-4.11.3-35.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-3.4.3-161.el7.centos.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-plugin-aliases-1.1.31-50.el7.noarch.rpm 
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-50.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-plugin-protectbase-1.1.31-50.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-50.el7.noarch.rpm

4、修改文件名

mv python-setuptools-0.9.8-7.el7.noarch.rpm  python-setuptools-0.9.8-7.el7.noarch
mv yum-utils-1.1.31-50.el7.noarch.rpm yum-utils-1.1.31-50.el7.noarch
mv yum-plugin-aliases-1.1.31-50.el7.noarch.rpm yum-plugin-aliases-1.1.31-50.el7.noarch

5、进行安装

rpm -Uvh --replacepkgs python*.rpm
 rpm -Uvh --replacepkgs rpm-python*.rpm yum*.rpm

6、测试

[root@alice yum_python]# python
Python 2.7.5 (default, Oct 30 2018, 23:45:53) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 
 类似资料: