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:
-
Uninstall the old tools
$ sudo rm -rf /Library/Developer/CommandLineTools
-
Reinstall Xcode Command line tools
$ xcode-select --install
-
Install python using pyenv
$ pyenv install 3.9.5
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/
Solution 5
I was able to get away with above error by referring to Common build problems
brew install readline xz
xcode-select --install
brew install openssl
After this, I installed and initialized pyenv
brew install pyenv
-
pyenv init
(inside your project directory)
Finally install and activate required python
version
- pyenv install 3.6.6
-
pyenv local 3.6.6
(inside your project directory)
Here's the link to original thread #1188 on GitHub
by @Harry Moreno
y2k-shubham
"A Big-Shot is a Little-Shot who keeps on Shooting, So keep Trying" - Dr. APJ Abdul Kalam, [Wings of Fire] My Bio Science Lover Introvert Technology Enthusiast Know me Web: y2k-shubham About.Me: y2k-shubham Connect with me GitHub: y2k-shubham Disqus: y2k_shubham . LinkedIn: y2k-shubham Twitter: y2k_shubham . Instagram: y2k.shubham Facebook: y2k.shubham
Updated on November 20, 2021Comments
-
y2k-shubham over 2 years
While trying to install
Python 3.6.6
(forAirflow
) usingPyEnv
onMacOS
, I am encountering build failure with following stack-traceFile "/private/var/folders/6y/kf699bqj2sgcgjshb20fr5zh0000gn/T/python-build.20180721180716.86347/Python-3.6.6/Lib/xmlrpc/client.py", line 138, in <module> from xml.parsers import expat File "/private/var/folders/6y/kf699bqj2sgcgjshb20fr5zh0000gn/T/python-build.20180721180716.86347/Python-3.6.6/Lib/xml/parsers/expat.py", line 4, in <module> from pyexpat import * ModuleNotFoundError: No module named 'pyexpat' make: *** [install] Error 1 BUILD FAILED (OS X 10.13.6 using python-build 20180424) Inspect or clean up the working tree at /var/folders/6y/kf699bqj2sgcgjshb20fr5zh0000gn/T/python-build.20180721180716.86347 Results logged to /var/folders/6y/kf699bqj2sgcgjsh
I've followed the steps mentioned in the docs for setting-up
PyEnv
onMac
viaHomebrew
.
Environment / Framework versions
MacOS High Sierra 10.13.6
Homebrew 1.7.1
PyEnv 1.2.6
- Existing
Python
distributionsPython 2.7.15 [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Python 3.7.0 [Clang 9.0.0 (clang-900.0.39.2)] on darwin
-
brandonscript over 5 yearsMight work, but that's super destructive, and probably cause you even more problems in the end...
-
Vadim over 5 yearsin my case it doesn't work, the error remains the same
-
R Claven over 5 yearsThis works if you have the LATEST version of XCode AND if you have "agreed" to the new license!
-
wjwwood about 5 yearsI suppose that might work, but is that a good idea? Doesn't this prevent you from using different SDK versions at different times? Presumably Apple changed this for a reason...
-
psuzzi about 5 yearsAlso in my case did not work, but Srinivas Gowda solution did. Anyway, the link to the thread is useful.
-
osprey almost 5 yearsWorks. Hopefully it doesn't break other things.
-
Vladimir Jovanović almost 5 yearsThis is the only option that worked for me, but be cautious - after you perform this step, you need to recreate
include
dir and then reinstall everything from start with brew. Thanks @Tomer, this saved me from complete OS reinstall! -
NeilG almost 5 yearsThis is a known requirement for Mojave as described here github.com/pyenv/pyenv/wiki/Common-build-problems which I routinely completed during initial installation but still got the same error
-
Matt Browne almost 5 yearsWorks for Python 3.6.6 too. Thank you!
-
Kjell Hedström almost 5 yearsWorked great on Mojave 10.14.5. The other answers did not work.
-
Tachikoma over 4 yearsWorked great on macOS Mojave 10.14.6
-
WhooNo about 4 yearsUnfortunately, not working for me on Mojave with Python 3.7.3 or 3.5.2
-
Noble Polygon about 4 yearsThis worked to help me get the AWS ebs cli installed if you get this on Mac OS catalina
-
Srikanth almost 4 yearsWorked for me on macOS Catalina (10.15.3) with Python 3.7.3
-
Tony M over 3 yearsI tried this and it didn't work. The brew upgrade part worked fine (took a while) but then pyenv install 3.7.4 gave BUILD FAILED (OS X 11.1 using python-build 20180424) Inspect or clean up the working tree at /var/folders/m8...
-
Bendemann about 3 yearsAnybody cares to explain what this does to newbies :)?
-
Marcel Wilson about 3 yearsIs there some way to setup the environment so we dont have to include
SDKROOT
andMACOSX_DEPLOYMENT_TARGET
every time? -
Brian Garr about 3 yearsI tried every one of these on my M1 chip Mini, and none of them worked.
-
Brian Garr about 3 yearsfurther, I don't have a Packages folder under CommandLineTools
-
Moshe almost 3 yearsThe
--patch
is the only thing that worked for me. Thanks. -
Nasir over 2 yearsIf you're copy-pasting the snippet above, make sure to remove the new line at the end of the first line which can break the compilation
-
HamiltonPharmD over 2 yearsI can confirm this worked for me in MacOS Big Sur Ver 11.5.2. I uninstalled pyenv prior to performing the above steps to be safe then reinstalled after step 2 above with:
curl https://pyenv.run | bash
-
Julian H over 2 yearsThis worked for me, thanks.
-
Eric Aya over 2 yearsThis has already been mentioned in many other answers. When answering older questions that already have answers, please make sure you provide either a novel solution or a significantly better explanation than existing answers.
-
StatsNoob about 2 yearsThis works on Big Sur 11.6.4 as well
-
ScottWelker about 2 yearsThis worked for me, Monterey 12.3.1 with pyenv 3.9.6. I did not uninstall pyenv first.
-
Steve Vermeulen almost 2 yearsIn addition to these steps, I also had to run
brew install openssl
-
Mote Zart almost 2 yearsI get this:
By default, distutils will build C++ extension modules with "clang++".
With the errorchecking for clang++... no
. But clang/clang++ are 100% already installed globally. Running the code in this answer above prompts me to install clang, which seemed promising. Maybe my pyenv couldn't find clang++? But DOH! Still failedpyenv install
-
schroederadrian almost 2 yearsI was in the same situation of migrating and this was the only working solution.