pipはPythonに同梱されているパッケージマネージャです。本記事ではpipでパッケージをインストールする際に”WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.”と表示されインストールが失敗する場合の対処法を紹介します。
OpenSSL(libssl)をインストールする
前記のエラーは自身でソースからビルドしたPythonで発生します。Pythonをソースからビルドする際、一部のモジュールには外部ライブラリに依存しているものがあり、依存しているライブラリがOSにインストールされていない場合、そのモジュールはビルドされません。PythonのsslモジュールはOpenSSL(libssl)に依存しており、OpenSSLがインストールされていない場合はsslモジュールがビルドされません。このため、当該エラーが発生します。
エラーを解消するためには、OpenSSLをインストールした上で、あらためてPythonをビルドしてインストールする必要があります。Ubuntuの場合は以下のコマンドでOpenSSLをインストールします。
$ sudo apt-get install libssl-dev $ #または $ sudo apt install libssl-dev
OpenSSLのインストール後、Pythonのソースを再度ビルドしてインストールします。以下は一例です。
$ wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz $ tar -xzf Python-3.8.0.tgz $ cd Python-3.8.0/ $ ./configure $ make $ sudo make install
makeによるビルド完了後のログを見ると、ビルドされなかったモジュールを確認することができます。以下はOpenSSLのインストール前にmakeしたときのログの抜粋です。
Python build finished successfully! The necessary bits to build these optional modules were not found: _bz2 _curses _curses_panel _dbm _gdbm _hashlib _lzma _sqlite3 _ssl _tkinter _uuid readline To find the necessary bits, look in setup.py in detect_modules() for the module's name. … 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
抜粋の上部ではビルドできなかったモジュールの一覧が列挙されています。_sslモジュールが一覧に含まれており、ビルドされなかったことが確認できます。ログの下部でも別途ビルドできなかった旨が出力されています。次に、OpenSSLのインストール後にmakeしたときのログが以下になります。
Python build finished successfully! The necessary bits to build these optional modules were not found: _bz2 _curses _curses_panel _dbm _gdbm _lzma _sqlite3 _tkinter _uuid readline To find the necessary bits, look in setup.py in detect_modules() for the module's name.
sslモジュールのビルドが成功した証として、一覧から_sslが消えていること、sslモジュールがビルドできなかった旨の警告が消えていることが確認できます。こちらのPythonでは当該エラーは発生しません。
「“WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. “と表示されてpip installが失敗する」への1件のフィードバック
コメントは受け付けていません。