1、官网下载python 3.12.5
2、安装前检查 openssl
bash
openssl version
# OpenSSL 1.1.1f 31 Mar 2020
如果提示 openssl 1.1.1无需安装 openssl,否则需要安装,下载openssl
bash
tar -zxf openssl-1.1.1s.tar.gz
cd openssl-1.1.1s/
./config -fPIC --prefix=/usr/include/openssl enable-shared
make
make install
其中:
-fPIC: 位置无关代码
--prefix=: 路径 一般选 /usr/include/openssl
enbale-shared: 动态库
3、解压编译安装
bash
## 解压
sudo tar zxvf ython-3.12.5.tgz
## 创建目录
sudo mkdir /usr/local/apps/python/python-3.12.5
## 编译
suduo ./configure --prefix=/usr/local/apps/python/python-3.12.5 --enable-optimizations --with-zlib=/usr/include/ --with-openssl-rpath=auto --with-openssl=/usr/include/openssl OPENSSL_LDFLAGS=-L/usr/include/openssl OPENSSL_LIBS=-l/usr/include/openssl/ssl OPENSSL_INCLUDES=-I/usr/include/openssl
## ------ or ----------------------------
sudo ./configure --prefix=/usr/local/apps/python/python-3.12.5 --enable-optimizations --with-ssl-default-suites=openssl
## 安装
sudo make -j$(nproc)
sudo make altinstall
4、检测系统是否是当前版本,如果不是当前版本重新建立软链接
bash
#检测系统当前python3是否是3.12.5
python3
##如果部署建立重新建立软链接 建立软连之前先删除之前软链
sudo rm -i /usr/bin/python3
sudo rm -i /usr/bin/pip3
## 重新建立软链
sudo ln -s /usr/local/apps/python/python-3.12.5/bin/python3.12 /usr/bin/python3
sudo ln -s /usr/local/apps/python/python-3.12.5/bin/pip3.12 /usr/bin/pip3
5、配置python环境变量
bash
sudo vi ~/.bashrc
PYTHON_HOME=/usr/local/apps/python/python-3.12.5
PATH=$HOME/.local/bin:$HOME/bin:$PATH:$PYTHON_HOME/bin
PYTHONPYTH=$HOME/.local/lib/python3.12/site-packages
export PYTHON_HOME PATH PYTHONPATH
source ~/.bashrc
6、参考文档