pip is configured with locations that require TLS/SSL, however the ssl module in Python is not


系統是centos7.2

python3.6.2

 

問題描述
第一遍編譯安裝Python3.6的步驟如下:

#先安裝相關包:

yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make

#下載並編譯Python3:

wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz

tar -xvJf  Python-3.6.2.tar.xz

cd Python-3.6.2

./configure prefix=/usr/local/python3

make && make install

mv /usr/bin/python /usr/bin/python.bak  #備份原Python

ln -s /usr/local/python3/bin/python3 /usr/bin/python  #讓Python命令指向新編譯的python3

python -V  #確認該命令是否指向python3

python2 -V  #確認該命令是否指向原python2.7.5
因為執行yum需要python2版本,所以我們還要修改yum的配置,執行:

vi /usr/bin/yum

把#! /usr/bin/python修改為#! /usr/bin/python2

同理修改/usr/libexec/urlgrabber-ext-down

-------------------------------------------------------------------------

到此,Python3確實是安裝成功了,也能與2.7.5版並存。

但接下來通過pip(注:因為是Python3,所以實際使用pip3命令)安裝pymysql、requests時提示錯誤:

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

#pip3 install pymysql
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting pymysql
Could not fetch URL https://pypi.python.org/simple/pymysql/: There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping
Could not find a version that satisfies the requirement pymysql (from versions: )
No matching distribution found for pymysql
網上查找資料,第一種方案提示說,需要在make前,./configure那一步加一個“--with-ssl”的參數,但實際執行"./configure --with-ssl"后提示“configure: WARNING: unrecognized options: --with-ssl”。

==============划重點!==============

后來找到第二種方案,實測可行,需要在make前修改Modules/Setup文件,完整編譯步驟如下:

cd Python-3.6.2

make clean  #如果已經和我一樣編譯過一次,建議先執行此步驟,否則可省略。

./configure prefix=/usr/local/python3

修改./Modules/Setup文件(將如下四行的注釋去掉):

# 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
此外,因為用到的lib路徑是/usr/local/ssl,而默認情況下,編譯器只會使用/lib和/usr/lib這兩個目錄下的庫文件,所以還需要做以下事情:

vim /etc/ld.so.conf(這個文件記錄了編譯時使用的動態鏈接庫的路徑)

增加一行:/usr/local/ssl/lib(注:也可能已有,只需把雙引號去掉)

並執行 /sbin/ldconfig -v命令

make && make install

到此Python3重新編譯成功,並且再通過pip3安裝pymysql、requests等庫就不會提示如標題的錯誤了。

最后,執行Python操作數據庫的腳本,驗證一下環境是否正確。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM