一.下載源碼
https://www.python.org/ftp/python/
二.修改Setup文件
sudo apt-get install openssl libssl-dev
gedit Python-3.6.7/Modules/Setup.dist
line 205左右,把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=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
三.設置安裝位置,設置生成共享庫
./configure --prefix=~/Python367/Python367Install
–enable-shared
make
make install
gedit ~/.bashrc
添加
# added for python3.6.7 make shared
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:Your_Python367_Install_Path/lib
四.測試
.~/Python367/Python367Install/bin/python3
>>> import ssl