1. 查看OpenSSL是否存在或者版本是否符合要求
首先使用openssl version命令查看OpenSSL 是否安裝好,若安裝好查看版本是否符合要求,安裝python3.7,3.8 至少需要OpenSSL1.0.2版本

2. 升級OpenSSL
wget http://www.openssl.org/source/openssl-1.0.2r.tar.gz
tar zxvf openssl-1.0.2r.tar.gz
./config --prefix=~/openssl1.0.2r --openssldir=~/openssl1.0.2r/openssl no-zlib #這里的安裝目錄可以按照自己需要修改
cd openssl-1.0.2r
make && make install
echo "export LD_LIBRARY_PATH=~/openssl1.0.2r/lib:$LD_LIBRARY_PATH" >> ~/.bashrc
source ~/.bashrc
3.重新編譯安裝python3.7或3.8
這里以python3.7為例
wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tar.xz
tar xvf Python-3.7.4.tar.xz
cd Python-3.7.4
./configure --prefix=~/Python3.7.4
vim ./Modules/Setup
在Setup檔案中搜索SSL,找到相關內容替換成下面的!
# Socket module helper for socket(2)
_socket socketmodule.c
# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
SSL=~/openssl1.0.2r
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
注意: 對于python3.8需要把第2行換成_socket socketmodule.c timemodule.c
保存退出后就可以編譯安裝啦!
make && make install
echo "export PATH=~/Python3.7.4/bin:$PATH" >> ~/.bashrc
source ~/.bashrc
最后用pip3安裝就沒有報錯啦!
注意:本文安裝軟體的目錄都是默認的當前用戶目錄下即 ~/
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/258533.html
標籤:其他
上一篇:ubuntu常用命令匯總
