PyEnv BUILD FAILED installing Python on MacOS

Solution 1:

I had this problem with Mojave and Python 3.7.3.

This worked for me:

SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk MACOSX_DEPLOYMENT_TARGET=10.14 pyenv install 3.7.3

Solution 2:

The only way I could get it working is through the below prefixes before installing

CFLAGS="-I$(brew --prefix readline)/include -I$(brew --prefix openssl)/include 
-I$(xcrun --show-sdk-path)/usr/include" \
LDFLAGS="-L$(brew --prefix readline)/lib -L$(brew --prefix openssl)/lib" \
PYTHON_CONFIGURE_OPTS=--enable-unicode=ucs2 \
pyenv install -v 3.7.1

Solution 3:

I'm posting my solution for those who are trying to resolve this issue in 2021. I am using macOS Big Sur Version 11.5.1. For me, this worked:

  1. Uninstall the old tools

    $ sudo rm -rf /Library/Developer/CommandLineTools

  2. Reinstall Xcode Command line tools

    $ xcode-select --install

  3. Install python using pyenv

    $ pyenv install 3.9.5

enter image description here

Solution 4:

The accepted answer didn't work for me (Mojave) but this did:

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

Credit to http://www.blog.howechen.com/macos-mojave-pyenv-install-multi-version-build-failed-solution/