Python2.6.6升级到Python2.7.3

我这以CentOS6.5为例

1、先确认版本信息

[root@jerry ~]# python --version
Python 2.6.6
[root@jerry ~]# cat /etc/redhat-release
CentOS release 6.5 (Final)

2、运行脚本安装

[root@jerry ~]#sh Python.sh

#!/bin/bash
#CentOS6升级Python2.6.6到Python2.7的版本

#安装所有的开发工具包
yum groupinstall -y "Development tools"

#安装其它的必需包
yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel

#下载、编译和安装 Python 2.7.3
wget https://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz
tar zxf Python-2.7.3.tgz
cd Python-2.7.3
./configure
make && make install

#检查安装
/usr/local/bin/python2.7 -V

#默认 Python 2.7.3 会安装在 /usr/local/bin 目录下。
#而系统自带的 Python 是在 /usr/bin 目录下。

#先把系统默认的旧版 Python 重命名。
mv /usr/bin/python /usr/bin/python.old

#再删除系统默认的 python-config 软链接。
rm -f /usr/bin/python-config

#最后创建新版本的 Python 软链接。
ln -s /usr/local/bin/python /usr/bin/python
ln -s /usr/local/bin/python-config /usr/bin/python-config
ln -s /usr/local/include/python2.7/ /usr/include/python2.7

#为新版 Python 安装 setuptools
wget https://bootstrap.pypa.io/ez_setup.py -O - | python
#setuptools 正确安装完成后,easy_install 命令就会被安装在 /usr/local/bin 目录下了。

#为新版 Python 安装 pip
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py

#为新版 Python 安装 distribute 包(可选)
pip install distribute

#再次注意:升级 Python 可能会导致 yum 命令不可用。解决方法如下:
cp -r /usr/lib/python2.6/site-packages/yum /usr/local/lib/python2.7/site-packages/
cp -r /usr/lib/python2.6/site-packages/rpmUtils /usr/local/lib/python2.7/site-packages/
cp -r /usr/lib/python2.6/site-packages/iniparse /usr/local/lib/python2.7/site-packages/
cp -r /usr/lib/python2.6/site-packages/urlgrabber /usr/local/lib/python2.7/site-packages/
cp -r /usr/lib64/python2.6/site-packages/rpm /usr/local/lib/python2.7/site-packages/
cp -r /usr/lib64/python2.6/site-packages/curl /usr/local/lib/python2.7/site-packages/
cp -p /usr/lib64/python2.6/site-packages/pycurl.so /usr/local/lib/python2.7/site-packages/
cp -p /usr/lib64/python2.6/site-packages/_sqlitecache.so /usr/local/lib/python2.7/site-packages/
cp -p /usr/lib64/python2.6/site-packages/sqlitecachec.py /usr/local/lib/python2.7/site-packages/
cp -p /usr/lib64/python2.6/site-packages/sqlitecachec.pyc /usr/local/lib/python2.7/site-packages/
cp -p /usr/lib64/python2.6/site-packages/sqlitecachec.pyo /usr/local/lib/python2.7/site-packages/

#查看新的 Python 版本
python --version

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值