解決安裝python3.7.4報錯Can''t connect to HTTPS URL becau

簡述

從官網下載了Python3.7.4,直接編譯安裝後,使用pip3出現了報錯信息: Can't connect to HTTPS URL because the SSL module is not available

錯誤原因

在Python3.7之後的版本,依賴的openssl,必須要是1.1或者1.0.2之後的版本,或者安裝了2.6.4之後的libressl。


image.png

而本地的openssl依然是1.0.1e的。

?

1
2
[root@localhost ~]# openssl version
OpenSSL 1.0.1e-fips 11 Feb 2013


解決方法

上openssl官網下載1.0.2或者1.1之後的openssl包,編譯安裝。我選擇的是1.0.2r。

?

1
2
3
4
5
6
[root@localhost ~]# tar zxvf openssl-1.0.2r.tar.gz
[root@localhost ~]# ./config --prefix=/opt/openssl1.0.2r --openssldir=/opt/openssl1.0.2r/openssl no-zlib
[root@localhost ~]# make && make install
[root@localhost ~]# echo "/opt/openssl1.0.2r/lib" >> /etc/ld.so.conf
[root@localhost ~]# ldconfig -v


注意:編譯openssl1.0.2r的時候建議加上no-zlib,否則後面可能會出現undefined symbol: SSL_CTX_get0_param錯誤

安裝python3.7

下載Python包,編譯

?

1
2
3
[root@localhost ~]# tar xvf  Python-3.7.4.tar.xz
[root@localhost ~]# cd Python-3.7.4;./configure --prefix=/data/tools/Python3.7.4


編譯完成後不要make,先修改Python源碼包中ssl的參數

打開源碼解壓目錄中的 Modules/Setup ,直接搜索 SSL= ,將SSL=後面的目錄改爲前面openssl的安裝目錄,並把下面三行的註釋去掉。

?

1
2
3
4
5
[root@localhost ~]# vim Modules/Setup
SSL=/opt/openssl1.0.2r
_ssl _ssl.c \
    -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
    -L$(SSL)/lib -lssl -lcrypto


改完之後就在解壓目錄直接make就行了。

?

1
2
3
4
5
6
7
8
9
10
[root@localhost ~]# make && make install
[root@localhost ~]# echo "export PATH=/data/tools/Python3.7.4/bin:$PATH" >> ~/.bashrc
[root@localhost ~]# source ~/.bashrc
[root@localhost ~]# pip3 list
Package  Version
---------- -------
pip    19.0.3
setuptools 40.8.0
You are using pip version 19.0.3, however version 19.2.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

總結

以上所述是小編給大家介紹的解決安裝python3.7.4報錯Can''t connect to HTTPS URL because the SSL module is not available,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回覆大家的。在此也非常感謝大家對腳本之家網站的支持!


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章