Centos7.4下重新安装yum和python

2022/1/14 7:05:56

本文主要是介绍Centos7.4下重新安装yum和python,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

Centos7.4下重新安装yum和python

注意自己的Centos版本

# cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core) 

一、原因

一次意外的python升级导致了yum不能使用,这就导致通过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.

通过各种尝试无果,所以最后重新安装了下python和yum。

其中python版本为:2.7.5

yum版本为:3.4.3

下面是安装过程记录。

二、下载软件

进入到Centos的页面,根据自己的centos版本,找到对应的安装包。本次系统所需要的下载链接为:https://vault.centos.org/7.4.1708/os/x86_64/Packages/

点击进入下面链接,分别下载所需要的rpm包,总共11个rpm包8个python所需要的包,以及3个yum所需要的包。软件包放在自己的下载目录下面:如/usr/local/soft

wget --no-check-certificate https://vault.centos.org/7.4.1708/os/x86_64/Packages/python-2.7.5-58.el7.x86_64.rpm
wget --no-check-certificate https://vault.centos.org/7.4.1708/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
wget --no-check-certificate http://vault.centos.org/7.4.1708/os/x86_64/Packages/python-pycurl-7.19.0-19.el7.x86_64.rpm
wget --no-check-certificate http://vault.centos.org/7.4.1708/os/x86_64/Packages/python-devel-2.7.5-58.el7.x86_64.rpm
wget --no-check-certificate http://vault.centos.org/7.4.1708/os/x86_64/Packages/python-libs-2.7.5-58.el7.x86_64.rpm
wget --no-check-certificate http://vault.centos.org/7.4.1708/os/x86_64/Packages/python-urlgrabber-3.10-8.el7.noarch.rpm
wget --no-check-certificate http://vault.centos.org/7.4.1708/os/x86_64/Packages/rpm-python-4.11.3-25.el7.x86_64.rpm
wget --no-check-certificate http://vault.centos.org/7.4.1708/os/x86_64/Packages/rpm-python-4.11.3-25.el7.x86_64.rpm

wget  --no-check-certificate https://vault.centos.org/7.4.1708/os/x86_64/Packages/yum-3.4.3-154.el7.centos.noarch.rpm
wget  --no-check-certificate https://vault.centos.org/7.4.1708/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget  --no-check-certificate https://vault.centos.org/7.4.1708/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-42.el7.noarch.rpm

三、卸载原来系统里面安装的python和yum

3.1 删除现有的python

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

#删除所有残余文,xargs,允许你对输出执行其他某些命令
whereis python |xargs rm -frv

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

3.2 删除现有的yum

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

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

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

四、 安装

rpm -Uvh --replacepkgs python*.rpm

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

五、验证

5.1 python验证

# python
Python 2.7.5 (default, Aug  4 2017, 00:39:18) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

5.2 yum验证

# yum --version
3.4.3
  Installed: rpm-4.11.3-48.el7_9.x86_64 at 2021-12-28 02:19
  Built    : CentOS BuildSystem <http://bugs.centos.org> at 2021-11-24 16:33
  Committed: Michal Domonkos <mdomonko@redhat.com> at 2021-11-01

  Installed: yum-3.4.3-154.el7.centos.noarch at 2022-01-10 10:42
  Built    : CentOS BuildSystem <http://bugs.centos.org> at 2017-08-05 19:13
  Committed: CentOS Sources <bugs@centos.org> at 2017-08-01

  Installed: yum-plugin-fastestmirror-1.1.31-42.el7.noarch at 2022-01-10 10:42
  Built    : CentOS BuildSystem <http://bugs.centos.org> at 2017-08-11 10:23
  Committed: Valentina Mukhamedzhanova <vmukhame@redhat.com> at 2017-03-21

 



这篇关于Centos7.4下重新安装yum和python的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程