菜单

Administrator
Administrator
发布于 2024-07-11 / 53 阅读
0
0

CentOS误删默认Python2环境的解决方式

系统版本

CentOS Linux release 7.6.1810 (Core) (阿里云服务器预装版)

问题描述

在没配置好python3环境的情况下,误将系统自带的python2环境提前删除,导致yum报错且无法使用,因为yum本身需要python环境才能运行,故需要使用rpm重新安装python环境和yum。

操作步骤

删除所有yum和python残留文件

#强制清除已安装的 python 程序及其关联
rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps 

#删除所有 python 残余文件
whereis python |xargs rm -frv

#验证删除 python,返回无结果说明清除干净
whereis python

#强制清除已安装的 yum 程序及其关联
rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps

#删除所有 yum 残余文件
whereis yum |xargs rm -frv

#验证删除 yum,返回无结果说明清除干净
whereis yum

下载所需的依赖包并安装

我下载的文件列表如下,如果提示需要额外依赖再下载即可

  	libxml2-python-2.9.1-6.el7.5.x86_64.rpm
    python-2.7.5-89.el7.x86_64.rpm
    python-backports-1.0-8.el7.x86_64.rpm
    python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch.rpm
    python-chardet-2.2.1-3.el7.noarch.rpm
    python-devel-2.7.5-89.el7.x86_64.rpm
    python-iniparse-0.4-9.el7.noarch.rpm
    python-ipaddress-1.0.16-2.el7.noarch.rpm
    python-kitchen-1.1.1-5.el7.noarch.rpm
    python-libs-2.7.5-89.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-10.el7.noarch.rpm
    python-virtualenv-15.1.0-4.el7_7.noarch.rpm
    rpm-4.11.3-45.el7.x86_64.rpm
    rpm-build-4.11.3-45.el7.x86_64.rpm
    rpm-build-libs-4.11.3-45.el7.x86_64.rpm
    rpm-libs-4.11.3-45.el7.x86_64.rpm
    rpm-python-4.11.3-45.el7.x86_64.rpm
    rpm-sign-4.11.3-45.el7.x86_64.rpm
    yum-3.4.3-168.el7.centos.noarch.rpm
    yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
    yum-plugin-aliases-1.1.31-54.el7_8.noarch.rpm
    yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm
    yum-plugin-protectbase-1.1.31-54.el7_8.noarch.rpm
    yum-utils-1.1.31-54.el7_8.noarch.rpm

# 首先cd到一个目录
cd /usr/local/example

# 执行下载命令下载依赖包
    wget "http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/libxml2-python-2.9.1-6.el7.5.x86_64.rpm"
    wget "http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-2.7.5-89.el7.x86_64.rpm"
    wget "http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-backports-1.0-8.el7.x86_64.rpm"
    wget "http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch.rpm"
    wget "http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-chardet-2.2.1-3.el7.noarch.rpm"
    wget "http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-devel-2.7.5-89.el7.x86_64.rpm"
    wget "http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm"
    wget "http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-ipaddress-1.0.16-2.el7.noarch.rpm"
    wget "http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-kitchen-1.1.1-5.el7.noarch.rpm"
    wget "http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-libs-2.7.5-89.el7.x86_64.rpm"
    wget "http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-pycurl-7.19.0-19.el7.x86_64.rpm"
    wget "http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-setuptools-0.9.8-7.el7.noarch.rpm"
    wget "http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-urlgrabber-3.10-10.el7.noarch.rpm"
    wget "http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-virtualenv-15.1.0-4.el7_7.noarch.rpm"
    wget "http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/rpm-4.11.3-45.el7.x86_64.rpm"
    wget "http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/rpm-build-4.11.3-45.el7.x86_64.rpm"
    wget "http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/rpm-build-libs-4.11.3-45.el7.x86_64.rpm"
    wget "http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/rpm-libs-4.11.3-45.el7.x86_64.rpm"
    wget "http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/rpm-python-4.11.3-45.el7.x86_64.rpm"
    wget "http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/rpm-sign-4.11.3-45.el7.x86_64.rpm"
    wget "http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-3.4.3-168.el7.centos.noarch.rpm"
    wget "http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm"
    wget "http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-plugin-aliases-1.1.31-54.el7_8.noarch.rpm"
    wget "http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm"
    wget "http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-plugin-protectbase-1.1.31-54.el7_8.noarch.rpm"
    wget "http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-54.el7_8.noarch.rpm"


# 使用rpm命令批量安装
rpm -Uvh --replacepkgs python*.rpm
rpm -Uvh --replacepkgs rpm-python*.rpm yum*.rpm --nodeps --force
rpm -Uvh --replacepkgs *.rpm

参考链接


评论