1.下载tar.gz包 地址:Python Release Python 3.12.1 | Python.org
2.上传包到linux服并解压
cd /home/local/
ll
tar -zxvf Python-3.12.1.tgz
3.安装编译python所需环境
yum install -y gcc
yum install -y zlib*
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
4.编译python并指定安装目录
cd Python-3.12.1/
./configure --prefix=/usr/local/python3 --with-ssl
make
make install# 在usr/bin创建指向usr/local/python的软链接
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
5.查看python版本
python --version
python3 --version