我的系统是RHEL7,改了Centos的yum源,安装python3后发现ssl经常出问题,pip无法从网站下载第三方库,常出现以下这种类型的提示:
[root@localhost ~]# pip3 install virtualenv
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting virtualenv
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/virtualenv/
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/virtualenv/
原因是所有openssl的版本为OpenSSL 1.0.1e-fips 11 Feb 2013,而python3.7需要的openssl的版本为1.0.2或者1.1.x,需要对openssl进行升级,并重新编译python3.7.6。
从https://www.openssl.org/source/openssl-1.1.1-pre8.tar.gz下载openssl-1.1.1-pre8.tar.gz以后,将压缩包解压后放入/usr/local/目录下。然后切换目录:
[root@linuxprobe 桌面]# cd /usr/local/openssl-1.1.1-pre8/
然后编译到/usr/目录下:
[root@linuxprobe openssl-1.1.1-pre8]# ./config --prefix=/usr/ no-zlib
Operating system: x86_64-whatever-linux2
Configuring OpenSSL version 1.1.1-pre8 (0x10101008L) for linux-x86_64
Using os-specific seed configuration
Creating configdata.pm
Creating Makefile
**********************************************************************
*** ***
*** If you want to report a building issue, please include the ***
*** output from this command: ***
*** ***
*** perl configdata.pm --dump ***
*** ***
**********************************************************************
编译并安装:
[root@linuxprobe openssl-1.1.1-pre8]# make && make install
得益于我们选择的安装路径/usr/,很多配置全省了。现在查一下openssl的版本:
[root@linuxprobe lib]# openssl version
OpenSSL 1.1.1-pre8 (beta) 20 Jun 2018
成功。现在重新安装python3.7.6就行了。