事件的起因:安装了anaconda,环境总是用到/usr/bin/python,就把python删了,哪知道之后yum就不能用了
- 教训:通过合理配置环境变量使用python3,系统自带的python万万不能删
- 修复的前提:确认rpm命令可用
首先删除系统中所有的python和yum残余
参考博客
rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps
whereis python |xargs rm -frv
whereis python
rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps
whereis yum |xargs rm -frv
whereis yum
这个过程中,anaconda中的python也被删掉了…其实应该可以通过环境变量设置不删掉,但是还是删了,所以anaconda之后又要重装
通过Centos官网下载rpm安装包修复
参考博客2
查看系统版本号和架构
lsb_release -a
uname -m
找到官网对应的rpm包并下载
我的系统对应的网址 下载这些包
popt-devel-1.13-16.el7.x86_64.rpm
python-2.7.5-89.el7.x86_64.rpm
python2-rpm-macros-3-34.el7.noarch.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-rpm-macros-3-34.el7.noarch.rpm
python-setuptools-0.9.8-7.el7.noarch.rpm
python-srpm-macros-3-34.el7.noarch.rpm
python-urlgrabber-3.10-10.el7.noarch.rpm
修复python
rpm -ivh python*.rpm
修复成功
修复yum
首先要安装rpm-python
rpm -ivh rpm-python-4.11.3-45.el7.x86_64.rpm
报错
error: Failed dependencies:
rpm = 4.11.3-45.el7 is needed by rpm-python-4.11.3-45.el7.x86_64
查看系统安装的rpm版本号rpm -qa|grep rpm 由于我的rpm升级过,本来应该是rpm-4.11.3-45.el7 版本,但现在变成了 rpm-4.11.3-48.el7_9.x86_64 ,所以rpm-python-4.11.3-45.el7.x86_64.rpm 无法安装的
到updates 下面去找这个rpm 包,网址
果然找到了 安装
rpm -ivh rpm-python-4.11.3-48.el7_9.x86_64.rpm
Preparing...
Updating / installing...
1:rpm-python-4.11.3-48.el7_9
这就装好了 下载这些包
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
rpm -ivh yum*.rpm 报错,依赖没有装好
libxml2-python is needed by yum-utils-1.1.31-54.el7_8.noarch
下载libxml2-python-2.9.1-6.el7.5.x86_64.rpm 安装,报错版本不符,与已有的包冲突
Preparing...
package libxml2-2.9.1-6.el7_9.6.x86_64 (which is newer than libxml2-2.9.1-6.el7.5 .x86_64) is already installed
file /usr/bin/xmlcatalog from install of libxml2-2.9.1-6.el7.5.x86_64 conflicts w ith file from package libxml2-2.9.1-6.el7_2.3.x86_64
file /usr/bin/xmllint from install of libxml2-2.9.1-6.el7.5.x86_64 conflicts with file from package libxml2-2.9.1-6.el7_2.3.x86_64
file /usr/lib64/libxml2.so.2.9.1 from install of libxml2-2.9.1-6.el7.5.x86_64 con flicts with file from package libxml2-2.9.1-6.el7_2.3.x86_64
file /usr/bin/xmlcatalog from install of libxml2-2.9.1-6.el7.5.x86_64 conflicts w ith file from package libxml2-2.9.1-6.el7_9.6.x86_64
file /usr/bin/xmllint from install of libxml2-2.9.1-6.el7.5.x86_64 conflicts with file from package libxml2-2.9.1-6.el7_9.6.x86_64
file /usr/lib64/libxml2.so.2.9.1 from install of libxml2-2.9.1-6.el7.5.x86_64 con flicts with file from package libxml2-2.9.1-6.el7_9.6.x86_64
仍然去update上找,没有找到,最后在CSDN上找到的,花了9.9
rpm -ivh libxml2-python-2.9.1-6.el7_9.6.x86_64.rpm
尝试使用yum,发现可以了
|