先升级系统环境
sudo yum groupinstall -y "Development Tools"
sudo yum install -y openssl-devel bzip2-devel libffi-devel
再进入源码目录,下载源码安装包
cd /usr/src
sudo wget https://www.python.org/ftp/python/3.12.3/Python-3.12.3.tar.xz
解压后进入目录
sudo tar xvf Python-3.12.3.tar.xz
cd Python-3.12.3
配置升级安装选项
sudo ./configure --enable-optimizations
升级安装
sudo make altinstall
更新命令链接
sudo update-alternatives --install /usr/bin/python python /usr/local/bin/python3.12 1
sudo update-alternatives --install /usr/bin/pip pip /usr/local/bin/pip3.12 1
查看更新后的版本号
python --version