转载:Centos: 完美解决python升级导致的yum报错问题(相信我这是一篇有用的文章)
转载自:https://blog.csdn.net/qq_43238405/article/details/106479937
问题大致如下:
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:
错误原因:你现在安装的python跟yum所依赖的python不相符,请安装相对应的python。
@SmilePad博主的代码)
[root@test ~]# rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps ##强制删除已安装程序及其关联
[root@test ~]# whereis python |xargs rm -frv ##删除所有残余文件 ##xargs,允许你对输出执行其他某些命令
[root@test ~]# whereis python ##验证删除,返回无结果
- 1
- 2
- 3
- 删除现有的yum
[root@test ~]# rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps
[root@test ~]# whereis yum |xargs rm -frv
- 1
- 2
-
从中科,163或者阿里云镜像下载相对应的包
centos版本可以根据自己的版本去找对应Packages
如果不知道自己的系统版本,命令行输入这个cat /etc/redhat-release
中科: http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/
163 : http://mirrors.163.com/centos/7/os/x86_64/Packages/
阿里: https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/
[root@test ~]# rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps ##强制删除已安装程序及其关联
[root@test ~]# whereis python |xargs rm -frv ##删除所有残余文件 ##xargs,允许你对输出执行其他某些命令
[root@test ~]# whereis python ##验证删除,返回无结果
[root@test ~]# rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps
[root@test ~]# whereis yum |xargs rm -frv
从中科,163或者阿里云镜像下载相对应的包
centos版本可以根据自己的版本去找对应Packages
如果不知道自己的系统版本,命令行输入这个cat /etc/redhat-release
中科: http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/
163 : http://mirrors.163.com/centos/7/os/x86_64/Packages/
阿里: https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/
Python跟yum的安装包根据时间的变化版本也会变动,以下版本为2018.06.12使用,最新版本根据文件的前缀自行下载。
- 下载Python安装包(此处引用简书的@挨踢的懒猫大大的原话)
我们需要下载的rpm文件列表:
- python-libs-2.7.5-48.el7.x86_64.rpm,被python依赖
- python-2.7.5-48.el7.x86_64.rpm
- python-iniparse-0.4-9.el7.noarch.rpm, 被yum依赖
- python-pycurl-7.19.0-19.el7.x86_64.rpm, 被python-urlgrabber依赖
- python-urlgrabber-3.10-8.el7.noarch.rpm , 被yum依赖
- rpm-python-4.11.3-21.el7.x86_64.rpm , 被yum依赖
- 作者:挨踢的懒猫
链接:https://www.jianshu.com/p/89df82a5d74b
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
下载大家都会吧,用wget下载到服务器上,下载好了之后一定要按照上面的顺序依次安装。
安装命令
rpm -ivh xxx.rpm
- 1
- 下载yum安装包
yum安装包列表:
- yum-3.4.3-150.el7.centos.noarch.rpm, 就是它依赖了上面的python库
- yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
- yum-plugin-fastestmirror-1.1.31-40.el7.noarch.rpm
- 作者:挨踢的懒猫
链接:https://www.jianshu.com/p/89df82a5d74b
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
yum安装也按照顺序执行,在执行第一个rpm时, 结尾加上 --nodeps参数强制安装
此处图片转载自@有人敲门knocky

最后大功告成!!!
修复yum报错问题之后,如果还想安装python3.x 以及 pip3 请看此篇文章:
root@local:[/usr/bin] yum
***************************
You need to give some command
Usage: yum [options] COMMAND
List of Commands:
check Check for problems in the rpmdb
check-update Check for available package updates
clean Remove cached data
deplist List a package's dependencies
distribution-synchronization Synchronize installed packages to the latest available versions
downgrade downgrade a package
erase Remove a package or packages from your system
fs Acts on the filesystem data of the host, mainly for removing docs/lanuages for minimal hosts.
fssnapshot Creates filesystem snapshots, or lists/deletes current snapshots.
groups Display, or use, the groups information
help Display a helpful usage message
history Display, or use, the transaction history
info Display details about a package or group of packages
install Install a package or packages on your system
list List a package or groups of packages
load-transaction load a saved transaction from filename
makecache Generate the metadata cache
provides Find what package provides the given value
reinstall reinstall a package
repo-pkgs Treat a repo. as a group of packages, so we can install/remove all of them
repolist Display the configured software repositories
search Search package details for the given string
shell Run an interactive yum shell
swap Simple way to swap packages, instead of using shell
update Update a package or packages on your system
update-minimal Works like upgrade, but goes to the 'newest' package match which fixes a problem that affects your system
updateinfo Acts on repository update information
upgrade Update packages taking obsoletes into account
version Display a version for the machine and/or available repos.