LoginSignup
12
6

More than 5 years have passed since last update.

macOS Mojaveで pyenv のインストールに失敗するときの対処方法

Last updated at Posted at 2019-02-04

pyenv で 3.7.x をインストールしようとしたらエラーが発生したので解決方法のメモ

環境は MacOS Mojave(v10.14.3)。

TL;DR

たどり着いた解決方法は次の通り。

$ sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
$ brew install openssl@1.1
$ CONFIGURE_OPTS="--with-openssl=$(brew --prefix openssl@1.1)" pyenv install 3.7.1

以下、上記に至る経緯。

zlibのエラーが発生した

次のようなエラーが発生した。

$ pyenv install 3.7.1
〜 略 〜
  File "/private/var/folders/4x/swb9y49s0pjgb9glg4h566qh0000gn/T/python-build.20190204231156.47930/Python-3.7.1/Lib/ensurepip/__init__.py", line 27, in _run_pip
    import pip._internal
zipimport.ZipImportError: can't decompress data; zlib not available
make: *** [install] Error 1

Common build problems · pyenv/pyenv Wiki を参考に次のコマンドを実行した。

sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

これで、zlibのエラーは出なくなったのだが...

OpenSSLのエラーが発生した

今度は次のようなメッセージが出て、インストールできなかった。

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

Common build problems · pyenv/pyenv Wiki を参考に次の様にしてみたが、ダメだった。

CFLAGS="-I$(brew --prefix openssl)/include" LDFLAGS="-L$(brew --prefix openssl)/lib" pyenv install -v 3.7.1

ログを見ていると、このような記述があった。

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

でインストールしているOpenSSLを確認してみた。

$ openssl version
LibreSSL 2.6.4

うーん、これではダメだとログは言っている。
なので次を試した。

$ brew install openssl@1.1
$ CFLAGS="-I$(brew --prefix openssl@1.1)/include" LDFLAGS="-L$(brew --prefix openssl@1.1)/lib" pyenv install -v 3.7.1

これでもダメ。

Python 3.7.0 :: The Python ssl extension was not compiled. Missing the OpenSSL lib? · Issue #1184 · pyenv/pyenvを参考に次の様にするとインストールできた。

$ CONFIGURE_OPTS="--with-openssl=$(brew --prefix openssl@1.1)" pyenv install 3.7.1

ちなみに、3.7.2 も同様にしてインストールできた。

12
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
12
6