pyenv installがzlib not availableの場合の対応

pyenv 1.2.11

macOS Mojaveにpython環境を再構築しようとした際、

pyenv install 3.7.3

実行時に以下エラーが発生した時の対応の備忘録。

 

python-build: use openssl from homebrew

python-build: use readline from homebrew

Downloading Python-3.7.3.tar.xz...

-> https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz

Installing Python-3.7.3...

python-build: use readline from homebrew

 

BUILD FAILED (OS X 10.14.4 using python-build 20180424)

 

Inspect or clean up the working tree at /tmp/python-build.20190503190744.14468

Results logged to /tmp/python-build.20190503190744.14468.log

 

Last 10 log lines:

  File "/private/tmp/python-build.20190503190744.14468/Python-3.7.3/Lib/ensurepip/__main__.py", line 5, in <module>

    sys.exit(ensurepip._main())

  File "/private/tmp/python-build.20190503190744.14468/Python-3.7.3/Lib/ensurepip/__init__.py", line 204, in _main

    default_pip=args.default_pip,

  File "/private/tmp/python-build.20190503190744.14468/Python-3.7.3/Lib/ensurepip/__init__.py", line 117, in _bootstrap

    return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)

  File "/private/tmp/python-build.20190503190744.14468/Python-3.7.3/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

 

対応内容

xcode-selectにmacOS SDK headerがデフォルトで入っていないことが原因のようなので、マニュアルで以下インストールを実施。

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

 

参考記事
https://qiita.com/zreactor/items/c3fd04417e0d61af0afe