升级openssl
python从3.7开始,依赖了更新版本的ssl,centos7默认的ssl不够,不升级的话,会导致pip安装不了依赖
代码语言:sh复制cd /usr/local/src
# 下载openssl包,准备源码编译
wget --no-check-certificate https://www.openssl.org/source/openssl-1.1.1q.tar.gz
安装
代码语言:sh复制cd /usr/local/src
tar zxvf openssl-1.1.1q.tar.gz
cd openssl-1.1.1q
./config -fPIC shared zlib --prefix=/usr/local/openssl
make && make install
echo "/usr/local/lib64/" >> /etc/ld.so.conf
ldconfig
使用高版本替换系统默认的OpenSSL版本
代码语言:sh复制mv /usr/bin/openssl /usr/bin/openssl.old
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/openssl/include/openssl /usr/include/openssl
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
ldconfig -v
openssl version #查看版本
OpenSSL 1.1.1q 5 Jul 2022
安装python编译依赖
代码语言:sh复制sudo yum install -y gcc make cmake zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel xz xz-devel libffi-devel
下载python
代码语言:sh复制wget https://python.org/ftp/python/3.10.9/Python-3.10.9.tgz
tar -xzvf Python-3.10.9.tgz
# 创建安装目录
mkdir /usr/local/python310
cd Python-3.10.9
编译安装
代码语言:sh复制# 指定安装目录和openssl的目录
./configure --prefix=/usr/local/python310 --with-openssl=/usr/local/openssl
make && make install
# 替换python3和pip3的命令
rm /usr/bin/python3
rm /usr/bin/pip3
ln -s /usr/local/python310/bin/python3.10 /usr/bin/python3
ln -s /usr/local/python310/bin/pip3.10 /usr/bin/pip3
代码语言:sh复制# 清除安装包
cd ..
rm -rf Python-3.10.9