[SOLVED] pyenv install python stuck at “python-build: use zlib from xcode sdk”

Issue

This Content is from Stack Overflow. Question asked by Ian

I just installed brew and Xcode(13.4) today, however, I got warning when I want to download python with pyenv.

I install pyenv with

brew update
brew install pyenv

Then I want to download python, e.g. 3.8.13

pyenv install 3.8.13

When it reach to line “python-build: use zlib from xcode sdk”, it will stuck for a long time and send a warning like

$ pyenv install 3.8.13
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.8.13.tar.xz...
-> https://www.python.org/ftp/python/3.8.13/Python-3.8.13.tar.xz
Installing Python-3.8.13...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
WARNING: The Python lzma extension was not compiled. Missing the lzma lib?
Installed Python-3.8.13 to /Users/yianchen/.pyenv/versions/3.8.13

It also happened when installing 3.8.11 or 3.9.7 or something else.

Solution

Finally this patch works in installing 3.7.6 on macbook m1 using pyenv.

To install python 3.7.6 version in mac os 12+ , M1 chip, apple clang version 13+ using pyenv, create a file anywhere in your local and call it python-3.7.6-m1.patch and copy the contents(below) to that file and save it.

diff --git a/configure b/configure
index b769d59629..8b018b6fe8 100755
--- a/configure
+++ b/configure
@@ -3370,7 +3370,7 @@ $as_echo "#define _BSD_SOURCE 1" >>confdefs.h
   # has no effect, don't bother defining them
   Darwin/[6789].*)
     define_xopen_source=no;;
-  Darwin/1[0-9].*)
+  Darwin/[12][0-9].*)
     define_xopen_source=no;;
   # On AIX 4 and 5.1, mbstate_t is defined only when _XOPEN_SOURCE == 500 but
   # used in wcsnrtombs() and mbsnrtowcs() even if _XOPEN_SOURCE is not defined
@@ -5179,8 +5179,6 @@ $as_echo "$as_me:
 fi
 
 
-MULTIARCH=$($CC --print-multiarch 2>/dev/null)
-
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for the platform triplet based on compiler characteristics" >&5
 $as_echo_n "checking for the platform triplet based on compiler characteristics... " >&6; }
@@ -5338,6 +5336,11 @@ $as_echo "none" >&6; }
 fi
 rm -f conftest.c conftest.out
 
+if test x$PLATFORM_TRIPLET != xdarwin; then
+  MULTIARCH=$($CC --print-multiarch 2>/dev/null)
+fi
+
+
 if test x$PLATFORM_TRIPLET != x && test x$MULTIARCH != x; then
   if test x$PLATFORM_TRIPLET != x$MULTIARCH; then
     as_fn_error $? "internal configure error for the platform triplet, please file a bug report" "$LINENO" 5
@@ -9247,6 +9250,9 @@ fi
      ppc)
        MACOSX_DEFAULT_ARCH="ppc64"
        ;;
+     arm64)
+        MACOSX_DEFAULT_ARCH="arm64"
+       ;;
      *)
        as_fn_error $? "Unexpected output of 'arch' on OSX" "$LINENO" 5
        ;;
diff --git a/configure.ac b/configure.ac
index 49acff3136..2f66184b26 100644
--- a/configure.ac
+++ b/configure.ac
@@ -490,7 +490,7 @@ case $ac_sys_system/$ac_sys_release in
   # has no effect, don't bother defining them
   Darwin/@<:@6789@:>@.*)
     define_xopen_source=no;;
-  Darwin/1@<:@0-9@:>@.*)
+  Darwin/@<:@[12]@:>@@<:@0-9@:>@.*)
     define_xopen_source=no;;
   # On AIX 4 and 5.1, mbstate_t is defined only when _XOPEN_SOURCE == 500 but
   # used in wcsnrtombs() and mbsnrtowcs() even if _XOPEN_SOURCE is not defined
@@ -724,8 +724,7 @@ then
 fi
 
 
-MULTIARCH=$($CC --print-multiarch 2>/dev/null)
-AC_SUBST(MULTIARCH)
+
 
 AC_MSG_CHECKING([for the platform triplet based on compiler characteristics])
 cat >> conftest.c <<EOF
@@ -880,6 +879,11 @@ else
 fi
 rm -f conftest.c conftest.out
 
+if test x$PLATFORM_TRIPLET != xdarwin; then
+  MULTIARCH=$($CC --print-multiarch 2>/dev/null)
+fi
+AC_SUBST(MULTIARCH)
+
 if test x$PLATFORM_TRIPLET != x && test x$MULTIARCH != x; then
   if test x$PLATFORM_TRIPLET != x$MULTIARCH; then
     AC_MSG_ERROR([internal configure error for the platform triplet, please file a bug report])

NOW we can Install python 3.7.6 using pyenv as follows (need to be in the same directory as the patch file that we just created):

pyenv install --patch 3.7.6 < python-3.7.6-m1.patch

To install other python version on mac os 12+ , M1 chip, apple clang version 13+ using pyenv (not tested but should work)

Shallow clone the branch of python version you are interested in installing. go to https://github.com/python/cpython and find the versions available for cloning under “tags” dropdown

git clone https://github.com/python/cpython --branch v3.x.x --single-branch
cd cpython

Now make changes to the two files in it (configure.ac and configure). the git diff should look like the one shown above. The line numbers will be different based on which version of python you are installing, this git diff file is for 3.7.6 and can’t be directly used for other versions. for other versions of python, search for the exact line of code being edited/deleted in the exact file as shown in the above git diff and make the changes accordingly. then save the git diff in a new file as follows.

git diff > python-3.x.x-m1.patch

Now we can install that version using:

pyenv install --patch 3.x.x < python-3.x.x-m1.patch

Answered by Tirtha Das


This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 4.0.

people found this article helpful. What about you?