非root使用者解決python3.7, 3.8提示找不到ssl模組報錯的解決步驟(親測可行)
阿新 • • 發佈:2021-02-10
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安裝就沒有報錯啦!
注意:本文安裝軟體的目錄都是預設的當前使用者目錄下即 ~/