7
6

More than 3 years have passed since last update.

pyenvでPython 2系をインストールする際にOpenSSLのエラーとなる場合の対処方法

Last updated at Posted at 2020-07-07

pyenvでPython 2系をインストールしようとしたところ、OpenSSLに関するエラーとなりインストールできない事象に遭遇しました。
その際に私がとった対応方法を記しておきます。

この記事の前提

  • macOSを使用している
  • homebrewでOpenSSLをインストールしている

エラー

pyenvでPython2系をインストールしたところ、以下のようなエラーが発生しました。

$ pyenv install 2.7.10
python-build: use openssl from homebrew
python-build: use readline from homebrew

...省略...

ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?

Please consult to the Wiki page to fix the problem.
https://github.com/pyenv/pyenv/wiki/Common-build-problems


BUILD FAILED (OS X 10.15.5 using python-build 1.2.18-19-gcf81e5a0)

Missing the OpenSSL lib? とのことから、OpenSSLで問題が発生していることがわかります。

解決方法

私の環境でこのエラーが発生していた原因は、homebrewでインストールされているOpenSSLのバージョンが1.0系でないことが原因でした。
Python 2系のインストールにはOpenSSL 1.0系が必要になります。

OpenSSLのバージョン確認

brewでインストールされているOpenSSLのversionを調べてみましょう。

$ brew info openssl
openssl@1.1: stable 1.1.1g (bottled) [keg-only]

OpenSSLのアンインストール

OpenSSL 1.1を一時的にunintallします。

$ brew uninstall --ignore-dependencies openssl

--ignore-dependenciesを付ける理由は、依存関係を無視して強制的にアンインストールさせるためです。
(他のソフトウェアから依存されている場合、このオプションを付けないとアンインストールできない)

Python 2系のインストール

つづいて、pyenvにてPython 2系をインストールします。
pyenv側で勝手にOpenSSL1.0系をインストールしてくれるため、自分でOpenSSL1.0系をインストールする必要はありません。

$ pyenv install 2.7.10
Installing openssl-1.0.2k...
Installed openssl-1.0.2k to /Users/hogesuke/.anyenv/envs/pyenv/versions/2.7.10

OpenSSL 1.1をインストールし直す

Python 2系のインストールに成功したら、アンインストールしたOpenSSL 1.1をhomebrewでインストールし直しておきます。

$ brew install openssl

参考

7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6