报错:It‘s possible that the above module doesn‘t match the current version of Python, which is: 2.7.5

1、错误

  因卸载python造成yum不可使用,后来再重新切换yum依赖的python版本,依然出现报错,如下:

[root@yanshi bin]# 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, Aug 17 2020, 17:30:24) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]

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

在网上找了很多的方法,都没有成功,最后无奈之下,只能重新安装yum及其依赖的python。

2、Yum及其依赖的安装

1、清空python

rpm -qa|grep python|xargs rpm -e --allmatches --nodeps

whereis python|xargs rm -fr

xargs用法:管道实现的是将前面的stdout作为后面的stdin,但是有些命令不接受管道的传递方式,最常见的就是ls命令。有些时候命令希望管道传递的是参数,但是直接用管道有时无法传递到命令的参数位,这时候需要xargs,xargs实现的是将管道传输过来的stdin进行处理然后传递到命令的参数位上。也就是说xargs完成了两个行为:处理管道传输过来的stdin;将处理后的传递到正确的位置上。
rpm -qa <包名>: 查看安装的软件包
rpm -e <包名>:卸载安装包
–nodeps: 如果该RPM包的安装依赖其它包,即使其它包没装,也强迫安装
rpm -e --allmatches --nodeps <包的名字> :删除所有相同名字的包, 并忽略依赖,这里要删除的即rpm -qa|grep python查询的结果。
2、清空yum

rpm -qa|grep yum|xargs rpm -e --allmatches --nodeps

rm -rf /etc/yum.repos.d/*

whereis yum|xargs rm -fr

3、下载相应的RPM文件

下载地址:http://mirrors.163.com/centos/7/os/x86_64/Packages/

需要下载的文件有:

[root@yanshi soft]# ls
python-2.7.5-88.el7.x86_64.rpm          python-pycurl-7.19.0-19.el7.x86_64.rpm    rpm-python-4.11.3-43.el7.x86_64.rpm
python2-rpm-macros-3-32.el7.noarch.rpm  python-rpm-macros-3-32.el7.noarch.rpm     yum-3.4.3-167.el7.centos.noarch.rpm
python-devel-2.7.5-88.el7.x86_64.rpm    python-srpm-macros-3-32.el7.noarch.rpm    yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
python-iniparse-0.4-9.el7.noarch.rpm    python-urlgrabber-3.10-10.el7.noarch.rpm  yum-plugin-fastestmirror-1.1.31-53.el7.noarch.rpm
python-libs-2.7.5-88.el7.x86_64.rpm     rpm-4.11.3-43.el7.x86_64.rpm

4、python安装

rpm -ivh python-* rpm-*

5、安装yum

rpm -ivh yum-*

注意: 安装的过程,可能会出现依赖顺序的问题,按照提示先安装被依赖的软件即可。

6、验证yum命令
验证yum命令时,出现如下提示,说明yum安装成功了,但是需要配置下载源文件。

[root@yanshi soft]# yum install vim
找不到配置文件 /etc/yum/pluginconf.d/product-id.conf
找不到插件 product-id 的配置文件 
找不到配置文件 /etc/yum/pluginconf.d/search-disabled-repos.conf
找不到插件 search-disabled-repos 的配置文件 
找不到配置文件 /etc/yum/pluginconf.d/subscription-manager.conf
找不到插件 subscription-manager 的配置文件 
已加载插件:fastestmirror
Determining fastest mirrors
There are no enabled repos.
 Run "yum repolist all" to see the repos you have.
 To enable Red Hat Subscription Management repositories:
     subscription-manager repos --enable <repo>
 To enable custom repositories:
     yum-config-manager --enable <repo>

首先执行如下命令,下载默认的镜像源:

 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
 
 yum makecache
 
 yum -y update
3、其他

安装rpm-4.11.3-43.el7.x86_64出现如下提醒,说明有冲突,安装失败(其他安装失败,处理方式一样)。

[root@yanshi soft]#  rpm  -ivh python-urlgrabber-3.10-10.el7.noarch.rpm 
准备中...                          ################################# [100%]
	file /bin/rpm from install of rpm-4.11.3-43.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-43.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-43.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-43.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-43.el7.x86_64 conflicts with file from package rpm-4.11.3-35.el7.x86_64
[root@yanshi soft]# 

重新上面提醒,说明软件冲突,安装时,添加–replacefiles参数即可。

rpm -ivh rpm-4.11.3-43.el7.x86_64.rpm --replacefiles
根据引用中的错误信息,错误提示了找不到满足要求的python3-dev版本。这可能是由于安装源的问题导致的。可以尝试更换安装源,例如使用国内的镜像源,如豆瓣源。可以使用以下命令进行安装: pip install python3-dev -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com 根据引用中的信息,你目前使用的测试框架是基于Python2.7.5,但你已经安装了Python3,导致部分库运行不兼容。此外,你在使用Python2安装库时也遇到了错误。这可能是因为库不支持Python2版本或者你在安装过程中遇到了其他问题。 最后,根据引用中的版本信息,你的pip版本为21.3.1,并且是在Python 3.7环境下安装的。 总结来说,你遇到的问题是找不到满足要求的python3-dev版本和在Python2环境下安装库时报错。解决方法包括更换安装源以及确认库是否支持Python2版本。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [ERROR: Could not find a version that satisfies the requirement python3-dev (from versions: none)](https://blog.csdn.net/william_andy/article/details/125728163)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [解决Python安装库报错: Could not find a version that satisfies the requirement mongoalchemy (from ...](https://blog.csdn.net/jlhx123456/article/details/114532071)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

姠惢荇者

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值