分享

centos7 python3.7 ssl_Python3.7安装(解决ssl问题)

 LibraryPKU 2021-12-26

注:本博文主要为转载后根据本人情况再加工

1 问题:

python3.7.2安装遇到如下ssl问题

>>> import ssl

Traceback (most recent call last):

File "", line 1, in

File "/usr/local/lib/python3.7/ssl.py", line 98, in

import _ssl # if we can't import it, let the error propagate

ModuleNotFoundError: No module named '_ssl'

2 解决办法

2.1安装依赖

yum groupinstall development

2.2 安装libressl代替openssl-devel

2.2.1 原因

由于系统的openssl是1.0.1的版本,对于python3.7太老了,需要更新为openssl1.0.2或者libressl2.64(不含)以后的版本,所以这里从libressl官网下载libressl源码,编译生成库文件代替系统的openssl1.0.1

2.2.2 安装libressl

下载libressl-2.8.0

./config –prefix=/usr/local/libressl

make

make intall

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

2.2.3 加载lib

cd /etc/ld.so.conf.d

新建文件

vim libressl-2.8.0.conf

#将以下行加入文件,并保存

/usr/local/libressl/lib

ldconfig -v #重新加载库文件

2.3安装python3.7

从官网下载python3.7的源码,

解压后进入Python-3.7.0

编译前需要设置环境变量(重要)

export LDFLAGS="-L/usr/local/libressl/lib"

export CPPFLAGS="-I/usr/local/libressl/include"

export PKG_CONFIG_PATH="/usr/local/libressl/lib/pkgconfig"

./configure –prefix=/usr/local/python3 –enable-shared CFLAGS=-fPIC

运行后会出现一堆信息:

注意最后的ssl检查,如下图所示:

2.4 处理异常

运行python3.7命令遇到:libpython3.7m.so.1.0: cannot open shared object file: No such file or d

echo /usr/local/python3.7/lib > /etc/ld.so.conf.d/python3.7.conf

ldconfig -v

2.4 验证

linux下gunicorn+flask项目的部署

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多