解决Python无法使用SSL模块

下载解压OpenSSL

wget https://www.openssl.org/source/openssl-1.1.1k.tar.gz
tar -zxvf openssl-1.1.1k.tar.gz

编译安装

cd openssl-1.1.1k/
./config --prefix=/usr/local/openssl
make && make install

替换最新OpenSSL

mv /usr/bin/openssl /usr/bin/openssl.old
mv /usr/lib64/openssl /usr/lib64/openssl.old
mv /usr/lib64/libssl.so /usr/lib64/libssl.so.old
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/openssl/include/openssl /usr/include/openssl
ln -s /usr/local/openssl/lib/libssl.so /usr/lib64/libssl.so
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
ldconfig -v

设置环境变量

export PATH=/usr/local/openssl/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/openssl/lib:$LD_LIBRARY_PATH

检查OpenSSL版本

openssl version
# OpenSSL 1.1.1k  25 Mar 2021

重新编译python

--prefix=/usr/local/python310 安装路径
--with-openssl=/usr/local/openssl 指定openssl
--enable-optimizations 启动优化, 如果编译报错就去掉

./configure --prefix=/usr/local/python310 --with-openssl=/usr/local/openssl --enable-optimizations
make && make install
无标签