Python 编程学习
\
在Cent0S 7.5下将Python 2.7.5升级到Python 3.6.6后,发现ssl模块不可用,具体详细信息如下所示:
检查发现openssl包已经安装了,然后按照网上的文章,修改Modules/Setup.dist中,找到SSL配置部分,如下截图所示
[root@db-server ~]# yum list installed |grep openssl\
openssl.x86_64 1:1.0.2k-19.el7 @base \
openssl-libs.x86_64 1:1.0.2k-19.el7 @base \
Socket module helper for SSL support; you must comment out the other
socket line above, and possibly edit the SSL variable:
SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
The crypt module is now disabled by default because it breaks builds
on many systems (where -lcrypt is needed), e.g. Linux (I believe).
#
First, look at Setup.config; configure may have set this for you.
_crypt _cryptmodule.c # -lcrypt # crypt(3); needs -lcrypt on some systems
这里需要取消注释部分(上图红框附近部分的设置),设置SSL路径,但是这个SSL的安装路径在哪里呢? 我查找了一下,发现openssl的安装路径如下:
尝试了几个路径,例如SSL=/usr/lib64/openssl ,然后重新编译安装Python,发现依然报错,
[root@db-server Python-3.6.6]# vi Modules/Setup.dist
SSL=/usr/lib64/openssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
cd /tmp/Python-3.6.6
./configure --prefix=/usr/local
make
make install
在Python的解压安装包里面,我查了一下setup.py , 搜索ssl关键字,发现有如下一些代码, 但是我在系统搜索了一下,居然找不到这些目录(ssl/include和/ssl/lib)和ssl.h这些文件。
后面才搞清楚,openssl包只包含了可执行部分,openssl-devel才包含了头文件、头文件参考、某些库文件等以及跟开发相关的东西。所以只安装了openssl包是找不到相应的头文件的,安装完openssl-devel之后,验证确认这些目录和文件已经存在了。
使用# rpm -ql openssl-devel 定位安装安装路径为 “ /usr/include/openssl ” ,修改安装路径的Modules/Setup.dist文件,修改后的部分如下所示(对比上面截图),然后重新编译安装Python后问题彻底解决。
Socket module helper for SSL support; you must comment out the other
socket line above, and possibly edit the SSL variable:
SSL=/usr/include/openssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl –lcrypto
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: