记一次误删centos 7.6系统自带的python2.7.5导致yum不能用的经历

目录

背景

现情况

接下来怎么做呢

成功

后记

感谢


背景

想要搭建Superset(一个开源的可视化展示项目,我的其它文章里面有介绍它),因为所需环境python 3.6+,而系统自带的是python2.7.5,我之前也知道python被很多代码作为底层的环境在用,这个Superset我之前已经搭建过了三次,之前是windows10,腾讯云(1c1g)和阿里云(2c8g)。但是这次就是手贱,手贱,手贱。

现情况

python命令、pip命令、yum 命令均已失效

所以先删除干净残余python2和yum,使用下面的命令

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

rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps  ##强制删除已安装程序及其关联
whereis yum |xargs rm -frv    ##删除

接下来怎么做呢

当然是下载重新安装python2.7.5和yum所需要的rpm包了

网址:http://mirrors.ustc.edu.cn/centos/找到对应的centos版本下载相应的包,我的是centos7.6,,但是这里显示的是7.7;因为经过一顿操作,7版本的所有依赖全部被我更新到7版本最新的rpm包了,所以这里显示也变成了 7.7.1908.

[root@instance-6tmb40ht yumPackage]# cat /etc/redhat-release 
CentOS Linux release 7.7.1908 (Core)

我的百度云linux系统所需的rpm包如下

wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-2.7.5-86.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-devel-2.7.5-86.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-libs-2.7.5-86.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-pycurl-7.19.0-19.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-setuptools-0.9.8-7.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-urlgrabber-3.10-9.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-backports-1.0-8.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-ipaddress-1.0.16-2.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/libxml2-python-2.9.1-6.el7_2.3.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-kitchen-1.1.1-5.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-chardet-2.2.1-3.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/rpm-python-4.11.3-40.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/yum-3.4.3-163.el7.centos.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/yum-utils-1.1.31-52.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-52.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/yum-plugin-protectbase-1.1.31-52.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/yum-plugin-aliases-1.1.31-52.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-rpm-macros-3-32.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-srpm-macros-3-32.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python2-rpm-macros-3-32.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/libxml2-python-2.9.1-6.el7_2.3.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/rpm-4.11.3-40.el7.x86_64.rpm

上面这还不多,我之前项目上,安装华为的大数据产品-FI的时候安装依赖,搞错了,然后就开始了漫长的rpm -ivh进程,最终手动把系统干废了,系统真的不经玩,无奈啊!

后来还是烦劳运维的小姐姐出马,重给克隆了台电脑,洒洒水呀!

上面的包全部下载下来了,命令可以一次复制过去哈,我傻乎乎的一个复制,因为不知道为啥网速太慢,虽然包不大。然后废话少说进行下一步

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

记住我说的话,安装rpm包能一条命令解决,绝不用多条,因为相互之间会有依赖。

成功

python -V
yum update   #更新完成就完事了

后记

[root@instance-6tmb40ht yumPackage]# rpm -ivh rpm-4.11.3-40.el7.x86_64.rpm
Preparing...                          ################################# [100%]
    file /bin/rpm from install of rpm-4.11.3-40.el7.x86_64 conflicts with file from package rpm-4.11.3-35.el7.x86_64
    file /usr/bin/rpm2cpio from install of rpm-4.11.3-40.el7.x86_64 conflicts with file from package rpm-4.11.3-35.el7.x86_64
    file /usr/bin/rpmdb from install of rpm-4.11.3-40.el7.x86_64 conflicts with file from package rpm-4.11.3-35.el7.x86_64
    file /usr/bin/rpmkeys from install of rpm-4.11.3-40.el7.x86_64 conflicts with file from package rpm-4.11.3-35.el7.x86_64
    file /usr/lib/rpm/rpmpopt-4.11.3 from install of rpm-4.11.3-40.el7.x86_64 conflicts with file from package rpm-4.11.3-35.el7.x86_64

解决办法,更新到最新版本,在你下载的包目录执行下面的这条命令即可
rpm -Uvh rpm-4.11.3-40.el7.x86_64.rpm --nodeps

 

感谢

https://blog.csdn.net/weixin_30256901/article/details/96581784

https://blog.csdn.net/weixin_30642561/article/details/96106342

你可能感兴趣的:(linux)