MangoCool

centos6.5系统 python2.6 升级到 python2.7

2015-11-16 11:21:46   作者:MangoCool   来源:MangoCool

下载Python2.7.8:

wget http://www.python.org/ftp/python/2.7.8/Python-2.7.8.tar.xz
解压:
tar -xvf Python-2.7.8.tar
安装:
# 进入目录:
cd Python-2.7.8
# 运行配置 configure:
./configure --prefix=/usr/local
# 编译安装:
make
make altinstall

查看版本:

python -V

这个时候的版本肯定还是显示之前的老版本,所以须要设置path:

建立软连接,使系统默认的Python指向Python2.7

mv /usr/bin/python /usr/bin/python2.6.6  
ln -s /usr/local/bin/python2.7 /usr/bin/python

重新检验Python版本,这次ok。

这个时候如果执行命令,会出现报错:

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.8 (default, Nov 16 2015, 10:15:47)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)]

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

这是因为yum是不兼容Python 2.7的,所以yum不能正常工作,我们需要指定yum的Python版本

解决系统Python软链接指向Python2.7版本:

#vim /usr/bin/yum
#修改 yum中的python 
将第一行  #!/usr/bin/python  改为 #!/usr/bin/python2.6
查找yum位置可以用:
which yum 


如果需要在Centos6下安装Python2.6版本,推荐rpm方式安装:

资源地址:http://www.rpmfind.net/linux/rpm2html/search.php?query=python

找到你需要的版本,安装命令:

#下载下来
wget ftp://195.220.108.108/linux/centos/6.7/os/x86_64/Packages/python-2.6.6-64.el6.x86_64.rpm
#安装
rpm -ivh python-2.6.6-64.el6.x86_64.rpm
#查看安装是否成功
rpm -qa|grep python


文章参考:http://ruiaylin.github.io/2014/12/12/python%20update/

                 http://blog.csdn.net/jcjc918/article/details/11022345

标签: centos python

分享:

上一篇Centos6.5 install yum

下一篇[Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"

关于我

崇尚极简,热爱技术,喜欢唱歌,热衷旅行,爱好电子产品的一介码农。

座右铭

当你的才华还撑不起你的野心的时候,你就应该静下心来学习,永不止步!

人生之旅历途甚长,所争决不在一年半月,万不可因此着急失望,招精神之萎葸。

Copyright 2015- 芒果酷(mangocool.com) All rights reserved. 湘ICP备14019394号

免责声明:本网站部分文章转载其他媒体,意在为公众提供免费服务。如有信息侵犯了您的权益,可与本网站联系,本网站将尽快予以撤除。