本ページはプロモーションが含まれています

Python pipインストールでHTTPSConnectionPool(host=’pypi.org’, port=443)のエラーメッセージが出た場合の対処について

Python開発環境

Pipインストール時に、
“There was a problem confirming the ssl certificate: HTTPSConnectionPool(host=’pypi.org’, port=443”
というエラーメッセージがでて少しハマったので、内容と解決策を共有します。
この記事をご覧になっているということはあなたも同じ問題で悩んで悩んでいるのかもしれません。
お役に立てれば幸いです。

スポンサーリンク

前提条件

  • Python3.8をソースからビルド

エラーメッセージ

pipコマンドでPythonモジュールをインストールしようとしたら下記のエラーが発生。

$ pip3.8 install numpy
Defaulting to user installation because normal site-packages is not writeable
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
  :
  :
Could not fetch URL https://pypi.org/simple/numpy/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/numpy/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
  :

試したこと、解決策

OpenSSLが入っていない?と思って確認したが、最新版がインストール済。

$ openssl version
OpenSSL 1.1.1  11 Sep 2018

$ apt install openssl
Reading package lists... Done
Building dependency tree       
Reading state information... Done
openssl is already the newest version (1.1.1-1ubuntu2.1~18.04.6).
openssl set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

調べてみると、libssl-devがインストールされていなかった為と判明。Pythonビルド中にsslモジュールがビルドされていなかった模様。

<参考記事:“WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. “と表示されてpip installが失敗する >

Pythonインストール時./configureコマンドとmakeコマンドのログを確認すると、それぞれ下記の記述がありました。

  • ./configureコマンドのログ
  •  :
    configure:17253: checking whether compiling and linking against OpenSSL works
    Trying link with OPENSSL_LDFLAGS=; OPENSSL_LIBS=; OPENSSL_INCLUDES=
    configure:17275: gcc -pthread -o conftest      conftest.c  -lcrypt -lpthread -ldl  -lutil -lm >&5
    conftest.c:381:10: fatal error: openssl/ssl.h: No such file or directory
        #include <openssl/ssl.h>
                ^~~~~~~~~~~~~~~
    compilation terminated.
     :
  • makeコマンドのログ
  •   :
    Could not build the ssl module!
    Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_PARAM_set1_host().
    LibreSSL 2.6.4 and earlier do not provide the necessary APIs, https://github.com/libressl-portable/portable/issues/381
       :

ということで、libssl-devを下記のようにインストール。

$ apt install libssl-dev

libssl-devインストール後のそれぞれのログは下記のようになりました。

  • ./configureコマンドのログ
  • configure:17253: checking whether compiling and linking against OpenSSL works
            Trying link with OPENSSL_LDFLAGS=-L/usr/lib; OPENSSL_LIBS=-lssl -lcrypto; OPENSSL_INCLUDES=-I/usr/include
  • makeコマンドのログ
  • 上記のメッセージが消えました。

python3.8を再度ビルドしたところ、pipインストールが出来るようになりました。

$ pip install numpy
Collecting numpy
    Downloading numpy-1.19.1-cp38-cp38-manylinux2010_x86_64.whl (14.5 MB)
        |████████████████████████████████| 14.5 MB 106 kB/s 
Installing collected packages: numpy
Successfully installed numpy-1.19.1

参考

このエラーはpipをインストールする際にも発生しましたが、同じ対処で解決出来ました。

PyPAの公式リファレンス を参照して下記コマンドでpipをインストール。

$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
$ python3.8 get-pip.py

その際、下記のエラーが発生(上記と同じメッセージ)。

$ python3.8 get-pip.py
Defaulting to user installation because normal site-packages is not writeable
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
    :
    :
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
    :

環境

  • OS: Ubuntu18.04LTS
  • Python3.8.4

まとめ

Python(に限りませんが)をインストールする時は依存ファイルはきちんと確認しましょう。

参考書籍

書籍でもう少し詳しく学びたい場合はこちらもどうぞ。筆者もかなり参考にさせてもらっています!

シェアする
ひびきをフォローする
Hbk project