CentOS 7.0 下 Python 2.7 升级到 Python 3.5

前段因为时间工作需要,要把 Centos 7.0 默认安装的 Python 2.7 升级到 Python 3.5。

具体操作如下:

# 安装 gcc gcc-c++ 等编译工具软件

yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc gcc-c++ wget -y

# 创建保存软件的目录

mkdir /home/tools && cd /home/tools/

# 下载 Python 3.5 版本

wget "https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tgz"

# 解压编译安装

tar -zxf Python-3.5.0.tgz
mkdir /usr/local/python3
cd Python-3.5.0
./configure --prefix=/usr/local/python3 make make install

 # 这里需要备份还原系统 yum 命令使用的 Pyhon2.7 

cd /usr/bin
mv python python.bak
ln -s /usr/local/python3/bin/python3 /usr/bin/python
ln -s /usr/local/python3/bin/python3 /usr/bin/python3

# 修改yum配置文件

编辑 /usr/bin/yum 和 /usr/libexec/urlgrabber-ext-down

改成: #!/usr/bin/python2.7

现在可以愉快地使用 Python 3.5 了~

原文地址:https://www.cnblogs.com/klvchen/p/8444103.html