macOS에서 pyenv로 python 설치시 오류 발생

현재 사용 중인 macOS 버전
<< 현재 사용 중인 macOS 버전 >>

현재 내가 사용하고 있는 MBPR의 macOS 버전은 10.14.4(베타)이다. 개인 작업을 하려고 pyenv로 python 3.7.2 버전을 설치하려고 하니 다음과 같은 오류가 발생했다.

$ pyenv install 3.7.2
python-build: use openssl from homebrew
python-build: use readline from homebrew

...(에러)

zipimport.ZipImportError: can't decompress data; zlib not available
make: *** [install] Error 1

글링을 해보니 macOS 10.14(Mojave)에서 발생하는 오류로 pyenv issue로 등록이 되었다고 한다. 원인은 Xcode 10부터는 Command line tools에서 /include에 헤더파일을 설치하지 않아서 발생한다고 한다. 명색이 애플 유료 개발자인데, 전혀 몰랐다.😑 관련 애플 문서 참고.

The command line tools will search the SDK for system headers by default. However, some software may fail to build correctly against the SDK and require macOS headers to be installed in the base system under /usr/include. If you are the maintainer of such software, we encourage you to update your project to work with the SDK or file a bug report for issues that are preventing you from doing so. As a workaround, an extra package is provided which will install the headers to the base system. In a future release, this package will no longer be provided. You can find this package at: /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg To make sure that you’re using the intended version of the command line tools, run xcode-select -s or xcode select -s /Library/Developer/CommandLineTools after installing.

애플 문서에서 설명된 것처럼 필요할 경우 별도의 명령어를 이용하여 설치해야 한다고 하길래… pyenv issue를 참고하여 해결하였다. 위와 같은 오류가 발생할 경우 다음의 명령어를 통해 헤더 파일을 설치하면 해결된다.

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