Python3.7安装(解决ssl问题)

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

1 问题:

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

>>> import ssl
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/ssl.py", line 98, in <module>
    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 验证

 

 https://blog.csdn.net/love_cjiajia/article/details/82254371

linux下gunicorn+flask项目的部署

https://blog.csdn.net/m0_38124502/article/details/78685941

posted @ 2020-02-26 16:28  风云_就是她了  阅读(4390)  评论(0编辑  收藏  举报