macOS Mojave Pyenv install multi-version build failed solution

Build Failed

On macOS Mojave, if you want to install multi-version of python. You might get build failed error.

The error would be like:

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

Inspect or clean up the working tree at /var/folders/wm/hm_v7w195c7ftkk6rjlk9qlc0000gn/T/python-build.20181208174645.70936
Results logged to /var/folders/wm/hm_v7w195c7ftkk6rjlk9qlc0000gn/T/python-build.20181208174645.70936.log

Last 10 log lines:
File "/private/var/folders/wm/hm_v7w195c7ftkk6rjlk9qlc0000gn/T/python-build.20181208174645.70936/Python-3.6.7/Lib/ensurepip/", line 5, in <module>
File "/private/var/folders/wm/hm_v7w195c7ftkk6rjlk9qlc0000gn/T/python-build.20181208174645.70936/Python-3.6.7/Lib/ensurepip/", line 204, in _main
File "/private/var/folders/wm/hm_v7w195c7ftkk6rjlk9qlc0000gn/T/python-build.20181208174645.70936/Python-3.6.7/Lib/ensurepip/", line 117, in _bootstrap
return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
File "/private/var/folders/wm/hm_v7w195c7ftkk6rjlk9qlc0000gn/T/python-build.20181208174645.70936/Python-3.6.7/Lib/ensurepip/", line 27, in _run_pip
import pip._internal
zipimport.ZipImportError: can't decompress data; zlib not available
make: *** [install] Error 1

On some webpage from StackOverflow, the solution will be used

xcode-select --install

But this cannot fix the issue on Mojave.


I saw this on GitHub, just post a blog to note this command.

On Mojave, just type:

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

and then install another environment, like

pyenv install 3.6.7