安装编译依赖:
sudo yum groupinstall “Development Tools”
sudo yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel
从 Python 官方 FTP 下载 Python 2.7.x 的源代码:
wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz
解压并编译:
tar xzf Python-2.7.18.tgz
cd Python-2.7.18
./configure –enable-optimizations
make
sudo make altinstall
验证安装:
检查 Python 2 是否安装成功:
python2.7 –version
cd /usr/bin
ln -s /usr/local/bin/python2.7 python