簡述python
從官網下載了Python3.7.4,直接編譯安裝後,使用pip3出現了報錯信息: Can't connect to HTTPS URL because the SSL module is not availablevim
錯誤緣由bash
在Python3.7以後的版本,依賴的openssl,必需要是1.1或者1.0.2以後的版本,或者安裝了2.6.4以後的libressl。ide
image.png網站
而本地的openssl依然是1.0.1e的。spa
?.net
1
2
|
[root@localhost ~]
# openssl version
OpenSSL
1.0
.
1e
-
fips
11
Feb
2013
|
解決方法code
上openssl官網下載1.0.2或者1.1以後的openssl包,編譯安裝。我選擇的是1.0.2r。orm
?htm
1
2
3
4
5
6
|
[root@localhost ~]
# wget http://www.openssl.org/source/openssl-1.0.2r.tar.gz
[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 ~]
# wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tar.xz
[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,但願對你們有所幫助,若是你們有任何疑問請給我留言,小編會及時回覆你們的。在此也很是感謝你們對腳本之家網站的支持!