问题之前在服务器上建服务环境没弄好,后来就直接把所有的python都给删除了;
带来的问题就是yum用不了,并且安装新的Python也报错,就把2.7给补救下,再试试
1. 查看centos版本
cat /etc/redhat-release
CentOS Linux release 7.9.2009
2. 使用wget分别下载python yum 的rpm包
按自己的版本下载即可。
我的版本对应的是https://vault.centos.org/7.9.2009/os/x86_64/Packages/
找到其中的相关包
把包下载到新建的目录下
# mkdir /usr/local/src/python
# cd /usr/local/src/python
目录文件如下:
wget http://vault.centos.org/7.9.2009/os/x86_64/Packages/python-backports-1.0-8.el7.x86_64.rpm
wget http://vault.centos.org/7.9.2009/os/x86_64/Packages/python-2.7.5-89.el7.x86_64.rpm
wget http://vault.centos.org/7.9.2009/os/x86_64/Packages/libxml2-python-2.9.1-6.el7.5.x86_64.rpm
wget http://vault.centos.org/7.9.2009/os/x86_64/Packages/python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch.rpm
wget http://vault.centos.org/7.9.2009/os/x86_64/Packages/python-chardet-2.2.1-3.el7.noarch.rpm
wget http://vault.centos.org/7.9.2009/os/x86_64/Packages/python-devel-2.7.5-89.el7.x86_64.rpm
wget http://vault.centos.org/7.9.2009/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
wget http://vault.centos.org/7.9.2009/os/x86_64/Packages/python-ipaddress-1.0.16-2.el7.noarch.rpm
wget http://vault.centos.org/7.9.2009/os/x86_64/Packages/python-kitchen-1.1.1-5.el7.noarch.rpm
wget http://vault.centos.org/7.9.2009/os/x86_64/Packages/python-libs-2.7.5-89.el7.x86_64.rpm
wget http://vault.centos.org/7.9.2009/os/x86_64/Packages/python-pycurl-7.19.0-19.el7.x86_64.rpm
wget http://vault.centos.org/7.9.2009/os/x86_64/Packages/python-setuptools-0.9.8-7.el7.noarch.rpm
wget http://vault.centos.org/7.9.2009/os/x86_64/Packages/python-urlgrabber-3.10-10.el7.noarch.rpm
wget http://vault.centos.org/7.9.2009/os/x86_64/Packages/python-virtualenv-15.1.0-4.el7_7.noarch.rpm
wget http://vault.centos.org/7.9.2009/os/x86_64/Packages/rpm-4.11.3-45.el7.x86_64.rpm
wget http://vault.centos.org/7.9.2009/os/x86_64/Packages/rpm-build-4.11.3-45.el7.x86_64.rpm
wget http://vault.centos.org/7.9.2009/os/x86_64/Packages/rpm-build-libs-4.11.3-45.el7.x86_64.rpm
wget http://vault.centos.org/7.9.2009/os/x86_64/Packages/rpm-libs-4.11.3-45.el7.x86_64.rpm
wget http://vault.centos.org/7.9.2009/os/x86_64/Packages/rpm-python-4.11.3-45.el7.x86_64.rpm
wget http://vault.centos.org/7.9.2009/os/x86_64/Packages/rpm-sign-4.11.3-45.el7.x86_64.rpm
wget http://vault.centos.org/7.9.2009/os/x86_64/Packages/yum-3.4.3-168.el7.centos.noarch.rpm
wget http://vault.centos.org/7.9.2009/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://vault.centos.org/7.9.2009/os/x86_64/Packages/yum-plugin-aliases-1.1.31-54.el7_8.noarch.rpm
wget http://vault.centos.org/7.9.2009/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm
wget http://vault.centos.org/7.9.2009/os/x86_64/Packages/yum-plugin-protectbase-1.1.31-54.el7_8.noarch.rpm
wget http://vault.centos.org/7.9.2009/os/x86_64/Packages/yum-utils-1.1.31-54.el7_8.noarch.rpm
下载后总共26个文件,大约大小如图所示:
3 安装
rpm -Uvh --replacepkgs libxml2*.rpm --nodeps --force
rpm -Uvh --replacepkgs python*.rpm --nodeps --force
rpm -Uvh --replacepkgs rpm-python*.rpm yum*.rpm --nodeps --force
测试
# python -V
Python 2.7.5
参考
https://blog.csdn.net/qq_44665283/article/details/128838066