CentOS7误删自带python2或yum异常导致yum命令不可用的解决方法

CentOS7误删python2或yum异常yum命令不可用的解决方法

此次问题解决采用部分博主的资料,但是也没有完全按照一个文档来执行完成的,主要麻烦安装文件依赖的下载,故在此记录下。下载资料也打包好放在百度云,需要的自行下载。
1、问题描述
由于漏洞修复,删除自带的python,导致CentOS7的yum无法使用。

异常场景

执行yum命令出现如下异常提示

[root@0016]# yum
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:

   No module named yum

Please install a package which provides this module, or
verify that the module is installed correctly.

It's possible that the above module doesn't match the
current version of Python, which is:
2.7.5 (default, Oct 14 2020, 14:45:30) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]

If you cannot solve this problem yourself, please go to 
the yum faq at:
  http://yum.baseurl.org/wiki/Faq

原因

出现这个异常,原因不明,猜测:

1.缺少python2异常
2.yum软件异常

解决方案
先卸载、删除yum残留文件后,从阿里镜像仓库下载Centos7对应系统版本的yum包,然后进行安装

卸载、删除残留文件

1.强制删除python已安装程序及其关联
rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps

2.删除残余python文件
whereis python |xargs rm -frv

3.验证删除,返回为无结果
whereis python

4.删除现有yum
rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps

5.删除残余yum文件
whereis yum |xargs rm -frv

下载系统版本对应的yum包

1.查看系统信息
[root@0016]#lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 7.9.2009 (Core)
Release:        7.9.2009
Codename:       Core

下载的包的版本应与系统版本号对应的一致

1.可以选择到官网下载http://vault.centos.org/7.2.1511/os/x86_64/Packages/
也可以选择在另外一台同样的服务器上使用 yumdownloader下载,命令如下

yumdownloader  python python-libs python-devel python-devel python-pycurl python-urlgrabber python-setuptools rpm-python yum-utils yum yum-metadata-parser yum-plugin-aliases yum-plugin-protectbase yum-plugin-fastestmirror python-kitchen python-chardet

2.如果使用这条命令没有完全下载的,我是通过下面链接里面下载的
http://mirrors.163.com/centos/7/os/x86_64/Packages/

3、需要的文件
下载地址
https://pan.baidu.com/s/1gGdIrg6sHhWuGB00RYrgEQ
提取码:pgz7
在这里插入图片描述
批量安装相关的包
将所有的安装包拷贝到一个新建的文件夹,执行下面命令,上面下载部分依赖需要的不能遗漏,如果报错查找相关依赖。

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

正常执行结果如下
在这里插入图片描述测试
截止到此,yum就已经可以正常使用了
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
934909504: found 24 primes in [30000080, 30000279] Thread 123145942302208: found 24 primes in [30000140, 30000339] Thread 123145934909504: found 25 primes in [30000060, 30000259] Thread 123145942302208: found 24 primes in [30000020, 30000219在 CentOS 7 中,yum 和很多系统工具都是基于 Python 2.x 版本开发的,如果你] Thread 123145934909504: found 24 primes in [30000110, 30000309] Thread 123145942卸载Python 2.x 版本,那么会导致 yum 无法正常使用。为了解决这个302208: found 25 primes in [30000170, 30000369] Thread 123145934909504: found 24问题,你需要重新安装 Python 2.x 版本或者升级到 Python 3.x 版本。 如果你想重新 primes in [30000050, 30000249] Thread 123145942302208: found 24 primes in [30000120安装 Python 2.x 版本,可以使用以下命令: ``` sudo yum install python2 ``` 如果你想升, 30000319] Thread 123145934909504: found 25 primes in [30000090, 30000289] 级到 Python 3.x 版本,可以使用以下命令: ``` sudo yum install python3 ``` 安装完成后Thread 123145942302208: found 24 primes in [30000030, 30000229] Thread 123145934909,你需要将系统默认的 Python 版本切换到新安装的版本,可以使用以下命令: ``` sudo alternatives504: found 24 primes in [30000100, 30000299] Thread 123145942302208: found 25 primes --config python ``` 然后选择你要使用Python 版本即可。 另外,为了避免类似的 in [30000160, 30000359] Thread 123145934909504: found 24 primes in [30000080,问题发生,建议不要轻易卸载系统自带Python 版本,可以通过安装其他版本的 Python 来 30000279] Thread 123145942302208: found 24 primes in [30000140, 30000339] Thread满足自己的需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值