最近在看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不可用了,这下问题就大了,没有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
|
还是报错。。。
不过这次错误变了,变成了“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,如需转载请自行联系原作者