编译安装完Python3之后,使用pip来安装python库,发现了如下报错:

 
$ pip install numpy
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting numpy
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/numpy/
Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/numpy/
Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/numpy/
Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/numpy/
Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/numpy/
Could not fetch URL https://pypi.python.org/simple/numpy/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.python.org', port=443): Max retries exceeded with url: /simple/numpy/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)) - skipping
Could not find a version that satisfies the requirement numpy (from versions: )
No matching distribution found for numpy
 

网上说了一种解决方案,是在./configure 的时候,加上--with-ssl选项,然后重新编译安装,尝试了下:

$ ./configure --with-ssl
... ...
configure: WARNING: unrecognized options: --with-ssl
... ...

出了个警告:不可识别的--with-ssl选项。

./configure --help看了下确实也没发现这个选项,估计是版本不一致,不大想折腾这个版本问题了,决定换个思路。

尝试安装openssl:

$ sudo yum install openssl

安装成功之后,重新编译安装,依旧报这个错,但是在make的时候有了一些发现:

 
$ make
... ...
Python build finished successfully!
The necessary bits to build these optional modules were not found:
_bz2 _curses _curses_panel
_dbm _gdbm _lzma
_sqlite3 _ssl _tkinter
readline
To find the necessary bits, look in setup.py in detect_modules() for the module's name.

可以看到,这里虽然make成功了,但是报了很多模块缺失,查看下编译安装目录下的setup.py,搜索_ssl,可以定位到如下代码:

 
 843         # Detect SSL support for the socket module (via _ssl)
844 search_for_ssl_incs_in = [
845 '/usr/local/ssl/include',
846 '/usr/contrib/ssl/include/'
847 ]
848 ssl_incs = find_file('openssl/ssl.h', inc_dirs,
849 search_for_ssl_incs_in
850 )
851 if ssl_incs is not None:
852 krb5_h = find_file('krb5.h', inc_dirs,
853 ['/usr/kerberos/include'])
854 if krb5_h:
855 ssl_incs += krb5_h
856 ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs,
857 ['/usr/local/ssl/lib',
858 '/usr/contrib/ssl/lib/'
859 ] )
860
861 if (ssl_incs is not None and
862 ssl_libs is not None):
863 exts.append( Extension('_ssl', ['_ssl.c'],
864 include_dirs = ssl_incs,
865 library_dirs = ssl_libs,
866 libraries = ['ssl', 'crypto'],
867 depends = ['socketmodule.h']), )
868 else:
869 missing.append('_ssl')
 

可以看到,setup.py会在'/usr/local/ssl/include', '/usr/contrib/ssl/include/' 这两个目录里面搜索'openssl/ssl.h' 这个头文件,然后会在 '/usr/local/ssl/lib' 和 '/usr/contrib/ssl/lib/' 之中搜索 ssl 的 lib文件,搜索不到,会将_ssl加入missing这个数组里面,然后寻找missing调用的地方:

 
 313         if missing:
314 print()
315 print("Python build finished successfully!")
316 print("The necessary bits to build these optional modules were not "
317 "found:")
318 print_three_column(missing)
319 print("To find the necessary bits, look in setup.py in"
320 " detect_modules() for the module's name.")
321 print()
 

找到了上面报错时候的输出,很明显,是由于搜索不到ssl.h头文件或者搜索不到lib文件而导致的报错,但是我刚刚明明是装了openssl的啊,为啥还会报找不到呢?手动搜索下:

$ sudo find / -name ssl.h

没找到ssl.h,折腾了一番之后,找到了如下命令:

$ sudo yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel 

可以看到,这个命令安装的是openssl-devel,与我之前安装的openssl有所不同,查阅资料之后发现,openssl只包含了可执行部分,openssl-devel才包含了头文件、头文件参考、某些库文件等跟开发相关的东西。所以只安装openssl是找不到相应的头文件的,安装完之后,再次编译:

 
$ make clean
$ make
... ...
Python build finished successfully!
The necessary bits to build these optional modules were not found:
_dbm _gdbm _lzma
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
 

果然发现,缺失的模块少了很多。

继续安装:

$ sudo make install

安装完之后,重新执行pip:

$ pip install numpy
Collecting numpy
Downloading https://files.pythonhosted.org/packages/68/1e/116ad560de97694e2d0c1843a7a0075cc9f49e922454d32f49a80eb6f1f2/numpy-1.14.5-cp36-cp36m-manylinux1_x86_64.whl (12.2MB)
6% |██ | 747kB 10kB/s eta 0:17:52

至此,pip安装报错的问题解决。

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

转 Python3 ssl模块不可用的问题的更多相关文章

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

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

  2. Python升级后ssl模块不可用问题解决和浅析

    在Cent0S 7.5下将Python 2.7.5升级到Python 3.6.6后,发现ssl模块不可用,具体详细信息如下所示: [root@db-server ~]# pip list Packag ...

  3. Python3中无法导入ssl模块的解决办法

    这个问题,已经困扰我好几天了,本萌新刚开始接触python,想爬取几个网页试试,发现urllib无法识别https,百度后才知道要导入ssl模块,可是发现又报错了. 本人实在无法理解为什么会报错,因为 ...

  4. ubuntu下安装python3.6.5导入ssl模块失败

    1.问题 python安装完毕后,提示找不到ssl模块: [root@localhost ~]# python3 Python ( , ::) [GCC (Red Hat -)] on linux2 ...

  5. Python3编译安装ssl模块问题

    本文以Centos系统为例 1.确保linux系统中安装了ssl-devel包 2.编译安装ssl模块到Python3中 1.查看linux系统中是否安装了ssl-devel包 # 查看命令 rpm ...

  6. pip命令出现了问题,提示说找不到ssl模块

    Could not find a version that satisfies the requirement pygame (from versions: ) No matching distrib ...

  7. [转]python3之模块psutil系统性能信息

    转自:https://www.cnblogs.com/zhangxinqi/p/9106265.html 阅读目录 1.psutil模块安装 2.获取CPU信息 3.内存信息 4.磁盘信息 5.网络信 ...

  8. 解决centos6系统上python3—flask模块的安装问题

    Flask 是一个使用 Python 编写的轻量级 Web 框架(所以我们前面花了那么多时间安装 Python3 呀).它被称为微型架构,因为其使用非常简单的核心以及功能丰富的扩展.虽然 Flask ...

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

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

随机推荐

  1. Redis常见问题及解决方案

    在Redis的运维使用过程中你遇到过那些问题,又是如何解决的呢?本文收集了一些Redis的常见问题以及解决方案,与大家一同探讨. 码字不易,欢迎大家转载,烦请注明出处:谢谢配合 你的Redis有big ...

  2. spark streaming流式计算---监听器

    随着对spark的了解,有时会觉得spark就像一个宝盒一样时不时会出现一些难以置信的新功能.每一个新功能被挖掘,就可以使开发过程变得更加便利一点.甚至使很多不可能完成或者完成起来比较复杂的操作,变成 ...

  3. Tomcat 配置虚拟目录以及虚拟主机

    目录 虚拟目录 虚拟主机 虚拟目录 虚拟目录的功能 一般情况下,我们的打包后的项目都是放到tomcat/webapps目录下的,然后通过localhost:8080/project_name这个链接进 ...

  4. matlab学习笔记10_5 通用字符串操作和比较函数

    一起来学matlab-matlab学习笔记10 10_5 通用字符串操作和比较函数 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考书籍 <matlab 程序设计与综合应用>张 ...

  5. EasyNVR摄像机网页H5全平台无插件直播流媒体播放服务二次开发之接口鉴权示例讲解

    背景需求 EasyNVR的使用者应该都清楚的了解到,EasyNVR一个强大的功能就是可以进行全平台的无插件直播.主要原因在于rtsp协议的视频流(默认是需要插件才可以播放的)经由EasyNVR处理可以 ...

  6. [LeetCode] 1. Two Sum 两数和

    Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...

  7. [LeetCode] 567. Permutation in String 字符串中的全排列

    Given two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. I ...

  8. zabbix解决中文乱码

    解决中文乱码 yum install -y wqy-microhei-fonts #解决方法 中文乱码 \cp /usr/share/fonts/wqy-microhei/wqy-microhei.t ...

  9. Bazel安装及使用入门

    Bazel [文档][https://docs.bazel.build/versions/1.1.0/bazel-overview.html] MacOS安装 brew tap bazelbuild/ ...

  10. 【神经网络与深度学习】【计算机视觉】Faster R-CNN

    Faster R-CNN Fast-RCNN基本实现端对端(除了proposal阶段外),下一步自然就是要把proposal阶段也用CNN实现(放到GPU上).这就出现了Faster-RCNN,一个完 ...