CentOS64位下python2.6升级到2.7的详细教程

时间:2021-09-29 08:35:11

1)安装devtoolset

yum groupinstall "Development tools"
2) 安装编译Python需要的包


yum install zlib-devel
yum install bzip2-devel
yum install openssl-devel
yum install ncurses-devel
yum install sqlite-devel



3)下载并解压Python 2.7.9的源代码

cd /opt
wget --no-check-certificate https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tar.xz
tar xf Python-2.7.9.tar.xz
cd Python-2.7.9




4)编译与安装Python 2.7.9

./configure --prefix=/usr/local
make && make altinstall




5)配置软连接,让系统pyhon默认指向python2.7.9

mv /usr/bin/python /usr/bin/python2.6_temp

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

python -V # 查看Python 2.7.9



6)yum与python2.7不兼容,修改yum文件

vi /usr/bin/yum

将"!/usr/bin/python"改为"!/usr/bin/python2.6"



7)配置环境变量

vi /etc/profile

# 添加如下内容:

PY_HOME=/usr/local/bin/python2.7

export PATH=$PY_HOME/bin:$PATH



8)启动环境变量配置

source /etc/profile # 当前终端生效,reboot后才会完全生效

echo $PATH #查看环境变量中是否包含python路径



9)完美升级完成