Python3 import ssl报错解决方法

# requests支持https访问必须升级openssl为libressl
# 安装libressl依赖:
yum -y install libffi-devel
yum -y install zlib zlib-devel
yum -y install bzip2 bzip2-devel
yum -y install ncurses ncurses-devel
yum -y install readline readline-devel
yum -y install openssl openssl-devel
yum -y install openssl-static
yum -y install xz lzma xz-devel
yum -y install sqlite sqlite-devel
yum -y install gdbm gdbm-devel
yum -y install tk tk-devel
yum -y install wget

# 编译安装libressl-2.8.0
下载libressl-2.8.0.tar.gz
https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/
wget https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-2.8.0.tar.gz
tar xf libressl-2.8.0.tar.gz
cd libressl-2.8.0
./config --prefix=/usr/local/libressl && make && make install
rm -rf libressl-2.8.0 libressl-2.8.0.tar.gz
mv /usr/bin/openssl /usr/bin/openssl.bak
mv /usr/include/openssl /usr/include/openssl.bak
ln -sf /usr/local/libressl/bin/openssl /usr/bin/openssl
ln -sf /usr/local/libressl/include/openssl /usr/include/openssl
ln -sf /usr/local/libressl/lib/libssl.so.45 /usr/lib/
ln -sf /usr/local/libressl/lib/libcrypto.so.43 /usr/lib/

echo '/usr/local/libressl/lib' >/etc/ld.so.conf.d/libressl-2.8.0.conf
ldconfig -v #重新加载库文件

进入解压后的目录libressl-2.8.0
./config --prefix=/usr/local/libressl
make && make install
mv /usr/bin/openssl /usr/bin/openssl.bak
mv /usr/include/openssl /usr/include/openssl.bak
ln -sf /usr/local/libressl/bin/openssl /usr/bin/openssl
ln -sf /usr/local/libressl/include/openssl /usr/include/openssl
ln -sf /usr/local/libressl/lib/libssl.so.45 /usr/lib/
ln -sf /usr/local/libressl/lib/libcrypto.so.43 /usr/lib/

新建文件
vim /etc/ld.so.conf.d/libressl-2.8.0.conf
#将以下行加入文件,并保存
/usr/local/libressl/lib
重新加载库文件
ldconfig -v

重新编译python(requests不需要重新编译, ssl需要)先修改python源码的Module/Setup。需要将默认注释掉的关于ssl的5行取消,大约在53%处。

# CSV file helper
#_csv _csv.c
 
# Socket module helper for socket(2)
_socket socketmodule.c
 
# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
SSL=/usr/local/libressl
_ssl _ssl.c \
    -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
    -L$(SSL)/lib -lssl -lcrypto

./configure --prefix=/usr/local/python3.8 --enable-shared --enable-optimizations --with-openssl=/usr/local/libressl

参考链接:
      https://www.cnblogs.com/mengzhilva/p/11059329.html
      https://blog.csdn.net/yw804909465/article/details/106426261/
      https://www.dazhuanlan.com/2019/12/23/5e003e2e9ac89/
      https://blog.csdn.net/Scorpio921/article/details/82682757

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值