macOS pyenv install python BUILD FAILED zlib not available

結論

重安裝 Command Line Developer Tools,解決。

緣由

最近想試試新 Python 特性,使用 pyenv 來安裝最乾淨。但顯示以下訊息。

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

Inspect or clean up the working tree at /var/folders/3c/m8h770490flc9_ph2hp0bvfm0000gn/T/python-build.20180617120225.47506
Results logged to /var/folders/3c/m8h770490flc9_ph2hp0bvfm0000gn/T/python-build.20180617120225.47506.log

Last 10 log lines:
  File "/private/var/folders/3c/m8h770490flc9_ph2hp0bvfm0000gn/T/python-build.20180617120225.47506/Python-3.4.8/Lib/ensurepip/__main__.py", line 4, in 
    ensurepip._main()
  File "/private/var/folders/3c/m8h770490flc9_ph2hp0bvfm0000gn/T/python-build.20180617120225.47506/Python-3.4.8/Lib/ensurepip/__init__.py", line 209, in _main
    default_pip=args.default_pip,
  File "/private/var/folders/3c/m8h770490flc9_ph2hp0bvfm0000gn/T/python-build.20180617120225.47506/Python-3.4.8/Lib/ensurepip/__init__.py", line 116, in bootstrap
    _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
  File "/private/var/folders/3c/m8h770490flc9_ph2hp0bvfm0000gn/T/python-build.20180617120225.47506/Python-3.4.8/Lib/ensurepip/__init__.py", line 40, in _run_pip
    import pip
zipimport.ZipImportError: can't decompress data; zlib not available
make: *** [install] Error 1

找了一下發現這個 https://github.com/pyenv/pyenv/wiki/common-build-problems#build-failed-error-the-python-zlib-extension-was-not-compiled-missing-the-zlib ,想到最近有更新 xcode 。
使用 xcode-select --install 後解決。

留言