centos 上源码安装python3.7 ssl模块失败的问题

python 3.7安装完毕后,提示找不到ssl模块。

编译python时抛出问题如下,并且import ssl失败,无法使用pip在线安装:

-----------------------------------------------------------------------

The necessary bits to build these optional modules were not found:
_hashlib              _ssl
To find the necessary bits, look in setup.py in detect_modules() for the module's name.


The following modules found by detect_modules() in setup.py, have been
built by the Makefile instead, as configured by the Setup files:
_abc                  atexit                pwd
time


Could not build the ssl module!
Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_PARAM_set1_host().
LibreSSL 2.6.4 and earlier do not provide the necessary APIs, https://github.com/libressl-portable/portable/issues/381
----------------------------------------------------------------------------

解决方法:安装openssl1.0.2,修改module/Setup.dist  ssl 的准确路径,重新编译。

具体步骤:

1.先安装依赖库

yum install -y zlib zlib-dev openssl-devel sqlite-devel bzip2-devel libffi libffi-devel

2.安装openssl-devel

yum install openssl-devel或者 用源码安装openssl-devel 1.0.2版本

3.修改 Modules/Setup.dist文件

在python 源码目录下,修改 Modules/Setup.dist,把ssl对应的地方取消注释。如下。

注意:笔者遇到问题时开始按照其它教程用yum安装了openssl-devel1.0.2,不行,也用源码安装openssl-devel,好像是版本不对,也不行。反正就是要安装正确的openssl-devel版本,修改Modules/Setup.dist里面的准确的路径,重新./configure,然后编译,就可以了。

参考网页:

https://blog.csdn.net/qq_41714057/article/details/81326858

https://www.jianshu.com/p/3ec24f563b81

https://github.com/libressl-portable/portable/issues/381

https://www.cnblogs.com/mqxs/p/9103031.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值