CentOS升级python,从2.4到2.7

说明:
安装的CentOS 5.8,系统自带Python 2.4,现在需要升级到2.7。主要是为了学习pyhon用的,系统自带的python2.4实在太老了,有些语法已经改变。而python2.7作为稳定版本,于2010年发布,即使出现问题网上应该比较好找。

实现:

# wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2
# ./configure
# make && make install

 

# rm /usr/bin/python  //原来的/usr/bin/python2.4与/usr/bin/python是一致的,因此这里删除掉没关系。不放心可以重命名mv /usr/bin/python /usr/bin/python.bak
# ln -s /usr/local/bin/python2.7 /usr/bin/python

 

# python -V  //大写的V哦。查看python的版本,可以看到已经升到2.7
Python 2.7.3

 

# yum list installed  python  //但yum list install python可以看到
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.3 (default, Jan 30 2013, 14:30:05)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)]

If you cannot solve this problem yourself, please go to
the yum faq at:
  http://wiki.linux.duke.edu/YumFaq

发现yum不能用了,听说是因为yum依赖python2.4,具体还没去了解。

# vim /usr/bin/yum  //将
#!/usr/bin/python
改成
#!/usr/bin/python2.4

就可以继续使用yum了。这里/usr/bin/python不一定是2.4,有可能是其它的如2.6等等。这是你系统原来自带的python

发表评论

邮箱地址不会被公开。 必填项已用*标注