一、原因
因openssl 1.0.1存在安全问题,python3自3.7版本后要求依赖openssl 1.0.2以上或libressl;错误提示如下:python requires an openssl 1.0.2 or 1.1 compatible libssl with x509_verify_p
python3.7以上建议使用libressl代替openssl,故需通过源码编译安装libressl
二、解决
# 下载源码包 wget https://ftp.openbsd.org/pub/openbsd/libressl/libressl-3.0.2.tar.gz # 解压 tar -zxvf libressl-3.0.2.tar.gz cd libressl-3.0.2 # 配置安装路径 mkdir /usr/local/libressl ./configure --prefix=/usr/local/libressl # 安装 make -j8 make install # 创建软连接代替openssl mv /usr/bin/openssl /usr/bin/openssl.bak mv /usr/include/openssl /usr/include/openssl.bak ln -s /usr/local/libressl/bin/openssl /usr/bin/openssl ln -s /usr/local/libressl/include/openssl /usr/include/openssl echo /usr/local/libressl/lib >> /etc/ld.so.conf.d/libressl-3.0.2.conf ldconfig -v
验证是否安装完成
openssl version
设置环境变量
export ldflags="-l/usr/local/libressl/lib" export cppflags="-i/usr/local/libressl/include" export pkg_config_path="/usr/local/libressl/lib/pkgconfig"
配置编译安装python
./configure --prefix=/usr/local/python37 make make install
验证ssl 安装正确
import ssl没有报错
到此这篇关于python3中no module named _ssl的问题解决的文章就介绍到这了,更多相关python3 no module named _ssl内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论