在Cent0S 7.5下将Python 2.7.5升级到Python 3.6.6后,发现ssl模块不可用,具体详细信息如下所示:

[root@db-server ~]# pip list

Package    Version

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

pip        19.2.3 

setuptools 39.0.1 

WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)) - skipping

 

[root@db-server ~]# python -V

Python 3.6.6

 

>>> import ssl

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "/usr/local/lib/python3.6/ssl.py", line 101, in <module>

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

ModuleNotFoundError: No module named '_ssl'

>>> 

>>> import socket

>>> hasattr(socket,"SSL")

False

>>>

检查发现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的安装路径如下:

[root@db-server ~]# whereis openssl

openssl: /usr/bin/openssl /usr/lib64/openssl /usr/share/man/man1/openssl.1ssl.gz

[root@db-server ~]# rpm -ql openssl

/etc/pki/CA

/etc/pki/CA/certs

/etc/pki/CA/crl

/etc/pki/CA/newcerts

/etc/pki/CA/private

/etc/pki/tls/certs/Makefile

/etc/pki/tls/certs/make-dummy-cert

/etc/pki/tls/certs/renew-dummy-cert

/etc/pki/tls/misc/CA

/etc/pki/tls/misc/c_hash

/etc/pki/tls/misc/c_info

/etc/pki/tls/misc/c_issuer

/etc/pki/tls/misc/c_name

/usr/bin/openssl

/usr/share/doc/openssl-1.0.2k

/usr/share/doc/openssl-1.0.2k/FAQ

/usr/share/doc/openssl-1.0.2k/NEWS

/usr/share/doc/openssl-1.0.2k/README

/usr/share/doc/openssl-1.0.2k/README.FIPS

/usr/share/doc/openssl-1.0.2k/README.legacy-settings

/usr/share/licenses/openssl-1.0.2k

/usr/share/licenses/openssl-1.0.2k/LICENSE

/usr/share/man/man1/asn1parse.1ssl.gz

/usr/share/man/man1/ca.1ssl.gz

/usr/share/man/man1/ciphers.1ssl.gz

/usr/share/man/man1/cms.1ssl.gz

/usr/share/man/man1/crl.1ssl.gz

/usr/share/man/man1/crl2pkcs7.1ssl.gz

/usr/share/man/man1/dgst.1ssl.gz

/usr/share/man/man1/dhparam.1ssl.gz

/usr/share/man/man1/dsa.1ssl.gz

/usr/share/man/man1/dsaparam.1ssl.gz

/usr/share/man/man1/dss1.1ssl.gz

/usr/share/man/man1/ec.1ssl.gz

/usr/share/man/man1/ecparam.1ssl.gz

/usr/share/man/man1/enc.1ssl.gz

/usr/share/man/man1/errstr.1ssl.gz

/usr/share/man/man1/gendsa.1ssl.gz

/usr/share/man/man1/genpkey.1ssl.gz

/usr/share/man/man1/genrsa.1ssl.gz

/usr/share/man/man1/md2.1ssl.gz

/usr/share/man/man1/md4.1ssl.gz

/usr/share/man/man1/md5.1ssl.gz

/usr/share/man/man1/mdc2.1ssl.gz

/usr/share/man/man1/nseq.1ssl.gz

/usr/share/man/man1/ocsp.1ssl.gz

/usr/share/man/man1/openssl.1ssl.gz

/usr/share/man/man1/pkcs12.1ssl.gz

/usr/share/man/man1/pkcs7.1ssl.gz

/usr/share/man/man1/pkcs8.1ssl.gz

/usr/share/man/man1/pkey.1ssl.gz

/usr/share/man/man1/pkeyparam.1ssl.gz

/usr/share/man/man1/pkeyutl.1ssl.gz

/usr/share/man/man1/req.1ssl.gz

/usr/share/man/man1/ripemd160.1ssl.gz

/usr/share/man/man1/rsa.1ssl.gz

/usr/share/man/man1/rsautl.1ssl.gz

/usr/share/man/man1/s_client.1ssl.gz

/usr/share/man/man1/s_server.1ssl.gz

/usr/share/man/man1/s_time.1ssl.gz

/usr/share/man/man1/sess_id.1ssl.gz

/usr/share/man/man1/sha.1ssl.gz

/usr/share/man/man1/sha1.1ssl.gz

/usr/share/man/man1/sha224.1ssl.gz

/usr/share/man/man1/sha256.1ssl.gz

/usr/share/man/man1/sha384.1ssl.gz

/usr/share/man/man1/sha512.1ssl.gz

/usr/share/man/man1/smime.1ssl.gz

/usr/share/man/man1/speed.1ssl.gz

/usr/share/man/man1/spkac.1ssl.gz

/usr/share/man/man1/sslpasswd.1ssl.gz

/usr/share/man/man1/sslrand.1ssl.gz

/usr/share/man/man1/ts.1ssl.gz

/usr/share/man/man1/verify.1ssl.gz

/usr/share/man/man1/version.1ssl.gz

/usr/share/man/man1/x509.1ssl.gz

/usr/share/man/man5/config.5ssl.gz

/usr/share/man/man5/openssl.cnf.5ssl.gz

/usr/share/man/man5/x509v3_config.5ssl.gz

/usr/share/man/man7/des_modes.7ssl.gz

尝试了几个路径,例如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这些文件。

[root@db-server ~]# vi /tmp/Python-3.6.6/setup.py

    # Detect SSL support for the socket module (via _ssl)

        search_for_ssl_incs_in = [

                              '/usr/local/ssl/include',

                              '/usr/contrib/ssl/include/'

                             ]

        ssl_incs = find_file('openssl/ssl.h', inc_dirs,

                             search_for_ssl_incs_in

                             )

        if ssl_incs is not None:

            krb5_h = find_file('krb5.h', inc_dirs,

                               ['/usr/kerberos/include'])

            if krb5_h:

                ssl_incs += krb5_h

        ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs,

                                     ['/usr/local/ssl/lib',

                                      '/usr/contrib/ssl/lib/'

                                     ] )

 

        if (ssl_incs is not None and

            ssl_libs is not None):

            exts.append( Extension('_ssl', ['_ssl.c'],

                                   include_dirs = ssl_incs,

                                   library_dirs = ssl_libs,

                                   libraries = ['ssl', 'crypto'],

                                   depends = ['socketmodule.h']), )

        else:

            missing.append('_ssl')

[root@db-server ~]# ls -lrt /usr/lib64/openssl

total 0

drwxr-xr-x. 2 root root 218 Sep 20 07:00 engines

 

[root@db-server ~]# ls /usr/local/ssl

ls: cannot access /usr/local/ssl: No such file or directory

 

[root@db-server ~]# find / -name ssl.h

后面才搞清楚,openssl包只包含了可执行部分,openssl-devel才包含了头文件、头文件参考、某些库文件等以及跟开发相关的东西。所以只安装了openssl包是找不到相应的头文件的,安装完openssl-devel之后,验证确认这些目录和文件已经存在了。

[root@db-server ~]# rpm -qa | grep openssl-devel

[root@db-server ~]# rpm -qa | grep openssl

openssl-1.0.2k-19.el7.x86_64

openssl-libs-1.0.2k-19.el7.x86_64

 

[root@db-server ~]# yum list installed |grep openssl-devel

[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    

[root@db-server ~]# 

 

[root@db-server ~]# yum install 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

 

 

参考资料:

https://www.cnblogs.com/minglee/p/9232673.html

Python升级后ssl模块不可用问题解决和浅析的更多相关文章

  1. CENTOS下Python 升级后YUM无法使用的解决办法

    Python有很多实用的工具,安装依赖python版本较高,升级Python后导致yum无法使用. 原因: 系统自带的yum依赖Python老版本,升级后不兼容 解决办法: 1. 列出所有版本,确定老 ...

  2. python升级后pip 不可用 卸载pip

    python版本由2.6升级到2.7之后,用pip提示报错 找了一下原因,网上的版本很多.弄来弄去比较麻烦 来点简单粗暴的 1.卸载pip yum remove python-pip 2.下载 cur ...

  3. Python3 ssl模块不可用的问题

    编译安装完Python3之后,使用pip来安装python库,发现了如下报错: $ pip install numpy pip is configured with locations that re ...

  4. 转 Python3 ssl模块不可用的问题

      编译安装完Python3之后,使用pip来安装python库,发现了如下报错:   $ pip install numpy pip is configured with locations tha ...

  5. 如何解决python升级后yum报错

    当我们yum命令的时候,会提示 "File "/usr/bin/yum", line 30 except KeyboardInterrupt, e: ^ SyntaxEr ...

  6. python升级后带来的几个小问题

    1)python升级带来的yum异常:File "/usr/bin/yum", line 30 原因:这是因为yum采用Python作为命令解释器,这可以从/usr/bin/yum ...

  7. CentOS更换python版本后,yum不可用的问题

    因为yum调用了python,他的启动程序/usr/bin/yum就是一个python脚本 yum是不兼容 Python 2.7的,所以yum不能正常工作,我们需要指定 yum 的Python版本 将 ...

  8. python 升级后正确安装 pip

    由于服务器的python 版本是2.6.6 , 为了使用 twisted 升级至 2.7.13 , 如果此时直接用 yum install python-pip 安装 pip, 则实际pip 会安装在 ...

  9. python安装完毕后,提示找不到ssl模块的解决步骤

    转载自 醇酒醉影 python安装完毕后,提示找不到ssl模块: [root@localhost ~]# python2.7.5 Python 2.7.5 (default, Jun 3 2013, ...

随机推荐

  1. [TimLinux] JavaScript 引用类型——Date

    1. Date var now = new Date(); // 不传参数,获取当前日期.时间. now.getDay(); // 日期 now.getMonth(); // 月份 now.getFu ...

  2. 使用chole创建一个连接池

    using Chloe; using Chloe.Infrastructure; using Chloe.SqlServer; using System; using System.Collectio ...

  3. 【算法】331- JS洗牌算法

    点击上方"前端自习课"关注,学习起来~ 最近的一个塔罗牌项目中,有一个洗牌的需求,其实也就是随机打乱数组,遂网上搜了下,再此做个整理- 塔罗牌 举例来说,我们有一个如下图所示的数组 ...

  4. 前端小白要搞懂什么是HTML,看这一篇就够了

    本文是<HTML5与CSS3基础语法自学教程>的第一篇,首发于[前端课湛]微信公众号. 导读:本小节主要讲解 HTML 的基本信息,其中包含 HTML 概念.HTML 发展历程和 HTML ...

  5. Java关于赋值

    下面的程序有问题吗?如果有问题说明一下, 如果没有问题猜测一下运行结果: public static void main(String[] args){ short s = 1; s=s+1; Sys ...

  6. 解决visual studio换行(回车键)不能代码补全问题

    打开工具--选项:将标红的位置改为true即可.

  7. 从KafkaConsumer看看Kafka(一)

      Kafka的消息模型为发布订阅模型,消息生产者将消息发布到主题(topic)中,一个或多个消费者订阅(消费)该主题消息并消费,此模型中发布到topic中的消息会被所有消费者所订阅到,先介绍Kafk ...

  8. cuckoo沙箱技术分析全景图

    从事信息安全技术行业的小伙伴们都知道沙箱技术(有些也称沙盒),用来判断一个程序或者文件是否是恶意的病毒.木马.漏洞攻击exp或其他恶意软件.其原理简单来说就是提供了一个虚拟的环境,把分析目标放到这个虚 ...

  9. 微信小程序视图层介绍及用法

    一. 视图层 WXML(WeiXin Markup Language)是框架设计的一套标签语言,结合基础组件.事件系统,可以构建出页面的结构. 1.1. 数据绑定 1.1.1. 普通写法 <vi ...

  10. 创建基于ASP.NET core 3.1 的RazorPagesMovie项目(一)-创建和使用默认的模板

    声明:参考于asp.net core 3.1 官网(以后不再说明) 本教程是系列教程中的第一个教程,介绍生成 ASP.NET Core Razor Pages Web 应用的基础知识. 在本系列结束时 ...