python升级导致yum不可用 “ No module named yum”

简介:

最近在看python,虚拟机装的是Centos6.6,自带的python版本是2.6.6,打算升级到2.7。

我的升级过程大致如下:

  下载2.7源码包https://www.python.org/downloads/source/

  卸载旧的python,rpm -e python

  编译安装python2.7

整个过程没有遇到问题,但升级完后,再用yum安装软件时报如下错误

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@localhost python] # 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.13 (r266:84292, Jan 22 2014, 09:37:14) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)]
 
If you cannot solve this problem yourself, please go to 
the yum faq at:
   http: //yum .baseurl.org /wiki/Faq

yum不可用了,这下问题就大了,spacer.gif没有yum,安装rpm包特别费劲。

开始百度关键字“No module named yum”,出来很多帖子和博客,博客上边说的大概意思就是yum就基于python的,升级python后,yum与高版本的python不兼容,导致yum无法使用。博客上给出的方法都是修改/usr/bin/yum文件的头部,把/usr/bin/python修改为/usr/bin/python2.6就可以了,但我的情况是我把旧的python已经卸载了,于是又开始安装2.6版本的python。

安装好2.6.6版本的之后以为就好了,但是还是报有错误:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@localhost python] # 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.6.6 (r266:84292, Jan 22 2014, 09:37:14) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)]
 
If you cannot solve this problem yourself, please go to 
the yum faq at:
   http: //yum .baseurl.org /wiki/Faq

这就奇怪了,都已经把旧版本的装上了,还是不行。这时看到一篇博客是把python和yum都全部卸载后重新安装的。想想这也是个办法于是就又全部下载

1
2
whereis  python | xargs  rm  -rf
rpm -e --nodeps python

卸载后重新安装,从光盘镜像里找到python和yum的包

1
2
rpm -ivh --nodeps python*
rpm -ivh --nodeps yum*

这次总该好了吧,验证一下

1
2
3
4
5
6
7
8
9
10
[root@localhost python] # python
Python 2.6.6 (r266:84292, Jan 22 2014, 09:37:14) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type  "help" "copyright" "credits"  or  "license"  for  more  information.
>>>  import  yum
Traceback (most recent call last):
   File  "<stdin>" , line 1,  in  <module>
   File  "/usr/lib/python2.6/site-packages/yum/__init__.py" , line 23,  in  <module>
     import  rpm
ImportError: No module named rpm

还是报错。。。

spacer.gif不过这次错误变了,变成了“No module named rpm”

再次百度,看到有人说是缺少包:rpm -ivh rpm-python-4.8.0-37.el6.i686.rpm 

安装上面的包后一切yum恢复正常了。


那问题又来了难道因为yum就不升级python版本吗?当然不是。其实是我在安装新版python的时候把旧版本的也卸载了才导致这样的问题。

后来在不卸载2.6版本的python是,重新编译安装2.7版本,安装成功并且yum仍然可用。




      本文转自hbxztc 51CTO博客,原文链接:http://blog.51cto.com/hbxztc/1959506,如需转载请自行联系原作者



相关文章
|
13天前
|
Python
conda升级python版本
conda升级python版本
|
17天前
|
Ubuntu Python
ubuntu升级Python版本
现在,你已成功升级了Python版本并可以使用新版本进行开发和运行程序。
33 1
|
27天前
|
Python
IDA3.12版本的python,依旧报错IDAPython: error executing init.py.No module named ‘impRefer to the message win
IDA3.12版本的python,依旧报错IDAPython: error executing init.py.No module named ‘impRefer to the message win
|
5月前
|
Ubuntu Python
Python(六)使用pycharm创建项目报错:ModuleNotFoundError No module named distutils.util
在ubuntu上使用pycharm创建项目的时候报错: ModuleNotFoundError: No module named 'distutils.util'
629 0
|
2月前
|
文字识别 Python
python代码运行报错:No module named 'aliyunsdkcore'
用python调用阿里云图片OCR识别,使用的是阿里云官方给的传本地图片文件进行检测的代码,运行报错:No module named 'aliyunsdkcore'。在pycharm python软件包和终端里安装aliyunsdkcore这个模块都失败了。
|
5月前
|
数据采集 文字识别 Python
介绍一个打怪升级练习Python的网站,寓教于乐了属于是!
介绍一个打怪升级练习Python的网站,寓教于乐了属于是!
|
5月前
|
Kubernetes Python 微服务
Python3异常-AttributeError: module 'sys' has no attribute 'setdefaultencoding
Python3异常-AttributeError: module 'sys' has no attribute 'setdefaultencoding
46 0
|
17天前
|
缓存
yum 如何设置可以将安装的rpm包都缓存下来
【4月更文挑战第17天】yum 如何设置可以将安装的rpm包都缓存下来
40 0
|
1月前
|
Linux C语言
linux yum安装ffmpeg 图文详解
linux yum安装ffmpeg 图文详解
49 0
|
1月前
|
Linux
linux yum 安装rar和unrar
linux yum 安装rar和unrar
98 0