Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyEnv BUILD FAILED installing Python on MacOS

Tags:

pyenv

While trying to install Python 3.6.6 (for Airflow) using PyEnv on MacOS, I am encountering build failure with following stack-trace

File "/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 on Mac via Homebrew.


Environment / Framework versions

  • MacOS High Sierra 10.13.6
  • Homebrew 1.7.1
  • PyEnv 1.2.6
  • Existing Python distributions
    • Python 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
like image 274
y2k-shubham Avatar asked Jul 27 '18 05:07

y2k-shubham


People also ask

Do I need to install Python before Pyenv?

pyenv is a wonderful tool for managing multiple Python versions. Even if you already have Python installed on your system, it is worth having pyenv installed so that you can easily try out new language features or help contribute to a project that is on a different version of Python.

Does Pyenv compile Python?

python-build is a pyenv plugin that provides a pyenv install command to compile and install different versions of Python on UNIX-like systems. You can also use python-build without pyenv in environments where you need precise control over Python version installation.


2 Answers

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 
like image 172
Henrique Bastos Avatar answered Oct 05 '22 10:10

Henrique Bastos


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 
like image 44
Srinivas Gowda Avatar answered Oct 05 '22 10:10

Srinivas Gowda