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/