编译安装完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')
知识兔