安装新的Python3与系统自带的Python2共存
yum -y install gcc make patch gdbm-devel openssl-devel sqlite-devel readline-devel zlib-devel bzip2-devel
# 一定要安装openssl-devel,不然无法调用ssl模块
# 如果是安装Python 3.7版本还需要libffi-devel
yum install libffi-devel -y
下载Python3
wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz
可以使用迅雷下载再传到服务器上
新建程序目录
mkdir /usr/local/python3
解压并编译安装Python3
tar -xvJf Python-3.6.2.tar.xz
cd Python-3.6.2
./configure --prefix=/usr/local/python3 --enable-optimizations
make && make install
# --prefix 是预期安装目录
# --enable-optimizations 是优化选项(LTO,PGO等)
至此Python3和pip3已经安装好
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
此时使用python3命令就是执行python3,使用python命令就是执行自带的python2,pip亦然