CentOS7.x 源代码编译安装Python3

CentOS7.x 源代码编译安装Python3

首先下载Pyton3.10.6源代码包,核对包文件MD5以及解压文件

wget https://www.python.org/ftp/python/3.10.6/Python-3.10.6.tgz
md5sum Python-3.10.6.tgz
tar -zxvf Python-3.10.6.tgz

补充底层依赖项

yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel libdb4-devel libpcap-devel xz-devel libffi-devel

开始构建安装Python3, 如果报错把后面删除掉 "--enable-optimizations"

cd ~/Python-3.10.6
./configure --prefix=/usr/local/python310 --enable-optimizations
make && make install

安装好了配置环境变量

用户环境变量文件路径:~/.bash_profile
在PATH=.... 结尾加;$PATH:/usr/local/python310/bin
1661952908798.jpg

再创建Python3软链接

ln -s /usr/local/python310/bin/python3 /usr/bin/python3

最后测试一下

python3 -V
python3 --version