はじめに
pyenvでPythonバージョンを新しくインストールしようとしたらzlib not availableエラーが出るようになりました。
色々探して解決策を試して見ても上手くいかずようやくインストール出来たのでそのメモです。
環境
ProductName: Mac OS X
ProductVersion: 10.14.6
BuildVersion: 18G87
pyenv 1.2.16
再現
$ pyenv install 3.6.8
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.6.8.tar.xz...
-> https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tar.xz
Installing Python-3.6.8...
python-build: use readline from homebrew
BUILD FAILED (OS X 10.14.6 using python-build 20180424)
Inspect or clean up the working tree at /var/folders/qr/fspx_mhd2t3b04xf6s1jjh680000gn/T/python-build.20200107115925.41170
Results logged to /var/folders/qr/fspx_mhd2t3b04xf6s1jjh680000gn/T/python-build.20200107115925.41170.log
Last 10 log lines:
File "/private/var/folders/qr/fspx_mhd2t3b04xf6s1jjh680000gn/T/python-build.20200107115925.41170/Python-3.6.8/Lib/ensurepip/__main__.py", line 5, in <module>
sys.exit(ensurepip._main())
File "/private/var/folders/qr/fspx_mhd2t3b04xf6s1jjh680000gn/T/python-build.20200107115925.41170/Python-3.6.8/Lib/ensurepip/__init__.py", line 204, in _main
default_pip=args.default_pip,
File "/private/var/folders/qr/fspx_mhd2t3b04xf6s1jjh680000gn/T/python-build.20200107115925.41170/Python-3.6.8/Lib/ensurepip/__init__.py", line 117, in _bootstrap
return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
File "/private/var/folders/qr/fspx_mhd2t3b04xf6s1jjh680000gn/T/python-build.20200107115925.41170/Python-3.6.8/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
以下の記事を参考に解決策を試したんですが、なぜか上手くいかず。。。
https://qiita.com/zreactor/items/c3fd04417e0d61af0afe
たぶん既にインストールしてるからか互換性がないから駄目だよってことなんだとは思いますが。。。
$ sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
installer: Package name is macOS_SDK_headers_for_macOS_10.14
installer: Certificate used to sign package is not trusted. Use -allowUntrusted to override.
$ sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target / -allowUntrusted
installer: Package name is macOS_SDK_headers_for_macOS_10.14
installer: Installing at base path /
installer: The install failed (The Installer encountered an error that caused the installation to fail. Contact the software manufacturer for assistance.)
解決策
最終的に以下で対応しました。
同じ悩みを抱える方が救われますように(;人;)
# コマンドラインツールを削除
sudo rm -rf /Library/Developer/CommandLineTools
# コマンドラインツールを再インストール
xcode-select --install
# パッケージインストール
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /