问题描述
python3.9安装完毕时发现未编译ssl模块导致pip无法使用
解决方案
重新编译python源码并安装
安装方法
1. openssl 确认
-
版本确认
python 3.9.X需要openssl版本在 1.1+
-
openssl路径查看
在python编译时需要指定openssl的inlucde 、lib路径,可以用which openssl找到bin路径,然后到对应目录、或者系统include、lib下排查。
openssl 安装
我是实在没找到openssl include的目录位置,重新安装一次openssl
#下载源码包
wget https://www.openssl.org/source/openssl-1.1.1g.tar.gz
#解压
tar -zxvf openssl-1.1.1g.tar.gz
#进入文件夹
cd openssl-1.1.1g/
#配置指定安装目录
./config --prefix=/home/work/openssl
#编译安装
make -j8 && make install
# 设置环境变量
export PATH=/home/work/openssl/bin:$PATH
export LD_LIBRARY_PATH=/home/work/openssl/lib:$LD_LIBRARY_PATH
2. Python源码安装
python源码下载地址:https://www.openssl.org/source/
1)修改Modules/Setup 中SSL,SSL=后面的内容修改为自己的openssl安装目录
2)python源码编译
# 配置指定目录
./configure --prefix=/home/work/local/python-3.9.7 --with-openssl=/home/work/openssl --enable-shared --enable-optimizations
# 编译&安装
make -j8 && make install