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