编译安装Python3

安装yum-utils

1
sudo yum install yum-utils

使用yum-builddep为Python3构建环境,安装缺失的软件依赖

1
sudo yum-builddep python

下载Python3最新版本,当前为3.7.0

1
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz

生成Makefile

1
./configure --enable-optimizations --prefix=/usr/local/python3 --enable-shared CFLAGS=-fPIC

跳过单元测试

1
sed -i 's/test.regrtest/this/g' Makefile        # 此步骤屏蔽单元测试(耗时太长)

编译并安装

1
2
3
4
5
make -j4 && sudo make install
echo 'export PATH=$PATH:/usr/local/python3/bin' | sudo tee /etc/profile.d/python3.sh
echo '/usr/local/python3/lib' | sudo tee /etc/ld.so.conf.d/python3.conf
sudo ldconfig
source /etc/profile.d/python3.sh

验证

1
python3 -V