环境:
OS:Centos 7
1.安装依赖包
[root@localhost ~]# yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc
centos 7停止服务后,可以使用阿里云yum,参考如下:
https://www.cnblogs.com/hxlasky/p/18367611
2.升级openssl
[root@localhost ~]# openssl version
OpenSSL 1.0.2k-fips 26 Jan 2017
该版本是不支持安装python3.12的,需要升级到1.1.1w
升级可以参考如下连接(openssl升级到1.1.1w):
https://www.cnblogs.com/hxlasky/p/18573536
若openssl使用的是比较新的版本,比如openssl3.XX,安装部署参考如下:
https://www.cnblogs.com/hxlasky/p/18348968
说明:
虽然openssl官网推荐最新版本,但是安装python,执行make依然会报错,我建议下载安装python3.12时推荐的openssl 1.1.1版本.
3.下载python安装包并解压
下载
cd /soft
wget https://www.python.org/ftp/python/3.12.7/Python-3.12.7.tgz
tar -zxvf Python-3.12.7.tgz
4.把python移到/usr/local下面
[root@host134 soft]# mv Python-3.12.7 /usr/local/
5.编译安装
进入python目录
[root@host134 soft]#cd /usr/local/Python-3.12.7/
[root@host134 soft]#./configure --with-openssl=/usr/local/openssl ##这里指定新版本openssl安装的目录
[root@host134 soft]#make
[root@host134 soft]#make install
6.删除旧的软链接,创建新的软链接到最新的python
rm -rf /usr/bin/python
rm -rf /usr/local/bin/python
ln -s /usr/local/bin/python3.12 /usr/bin/python
ln -s /usr/local/bin/python3.12 /usr/local/bin/python
7.查看版本
[root@node2 Python-3.12.7]# python -V
Python 3.12.7