pyenv unable to install 3.9.6 on Monterey 12.3

3.3k views Asked by At

I see this is a recurring question and there are no new comments about this. I've been trying to install python 3.9.6 using pyenv on both archs arm64 and i386 - using Rosetta2, without success. As I am pretty new at this, I was not able to identify what is wrong, and I would like to confirm this is not a bug or compatibility issue of any sort.

Does anyone can help to get this going? I really need version 3.9.6 running on monterrey OS :(

debug below and build attempt log attached

Description MacOS Monterey 12.3: Rosetta 2: pyenv version 2.2.5: Python version 3.9.6: C Compiler information gcc 13.1.6 (clang also installed):

python-build: use [email protected] from homebrew
python-build: use readline from homebrew
Downloading Python-3.9.6.tar.xz...
-> https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tar.xz
Installing Python-3.9.6...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk

BUILD FAILED (OS X 12.3 using python-build 20180424)

Inspect or clean up the working tree at /var/folders/f3/32flyrb56gg5h45x3ntjrqpm0000gn/T/python-build.20220319140423.1512
Results logged to /var/folders/f3/32flyrb56gg5h45x3ntjrqpm0000gn/T/python-build.20220319140423.1512.log

Last 10 log lines:
checking for --with-cxx-main=... no
checking for clang++... no
configure:

By default, distutils will build C++ extension modules with "clang++".
If this is not intended, then set CXX on the configure command line.

checking for the platform triplet based on compiler characteristics... darwin
configure: error: internal configure error for the platform triplet, please file a bug report
make: *** No targets specified and no makefile found. Stop.

 Please attach the debug trace of the failing command as a gist:
trace.log:
+(/usr/local/bin/pyenv:23): enable -f /usr/local/bin/../libexec/pyenv-realpath.dylib realpath
+(/usr/local/bin/pyenv:30): '[' -z '' ']'
++(/usr/local/bin/pyenv:32): type -P greadlink readlink
++(/usr/local/bin/pyenv:32): head -1
+(/usr/local/bin/pyenv:32): READLINK=/usr/bin/readlink
+(/usr/local/bin/pyenv:33): '[' -n /usr/bin/readlink ']'
+(/usr/local/bin/pyenv:58): '[' -z /Users/edgar.pellizzon/.pyenv ']'
+(/usr/local/bin/pyenv:61): PYENV_ROOT=/Users/edgar.pellizzon/.pyenv
+(/usr/local/bin/pyenv:63): export PYENV_ROOT
+(/usr/local/bin/pyenv:65): '[' -z '' ']'
+(/usr/local/bin/pyenv:66): PYENV_DIR=/Users/edgar.pellizzon
+(/usr/local/bin/pyenv:69): '[' '!' -d /Users/edgar.pellizzon ']'
+(/usr/local/bin/pyenv:69): '[' '!' -e /Users/edgar.pellizzon ']'
++(/usr/local/bin/pyenv:73): cd /Users/edgar.pellizzon
++(/usr/local/bin/pyenv:73): echo /Users/edgar.pellizzon
+(/usr/local/bin/pyenv:73): PYENV_DIR=/Users/edgar.pellizzon
+(/usr/local/bin/pyenv:74): export PYENV_DIR
+(/usr/local/bin/pyenv:77): shopt -s nullglob
++(/usr/local/bin/pyenv:79): abs_dirname /usr/local/bin/pyenv
++(/usr/local/bin/pyenv:40): abs_dirname(): local path=/usr/local/bin/pyenv
++(/usr/local/bin/pyenv:44): abs_dirname(): '[' -n /usr/local/bin/pyenv ']'
++(/usr/local/bin/pyenv:45): abs_dirname(): cd_path=/usr/local/bin
++(/usr/local/bin/pyenv:46): abs_dirname(): [[ /usr/local/bin != /\u\s\r/\l\o\c\a\l/\b\i\n/\p\y\e\n\v ]]
++(/usr/local/bin/pyenv:47): abs_dirname(): cd /usr/local/bin
++(/usr/local/bin/pyenv:49): abs_dirname(): name=pyenv
+++(/usr/local/bin/pyenv:50): abs_dirname(): resolve_link pyenv
+++(/usr/local/bin/pyenv:36): resolve_link(): /usr/bin/readlink pyenv
++(/usr/local/bin/pyenv:50): abs_dirname(): path=../Cellar/pyenv/HEAD-986fe1a/bin/pyenv
++(/usr/local/bin/pyenv:44): abs_dirname(): '[' -n ../Cellar/pyenv/HEAD-986fe1a/bin/pyenv ']'
++(/usr/local/bin/pyenv:45): abs_dirname(): cd_path=../Cellar/pyenv/HEAD-986fe1a/bin
++(/usr/local/bin/pyenv:46): abs_dirname(): [[ ../Cellar/pyenv/HEAD-986fe1a/bin != ../\C\e\l\l\a\r/\p\y\e\n\v/\H\E\A\D-\9\8\6\f\e\1\a/\b\i\n/\p\y\e\n\v ]]
++(/usr/local/bin/pyenv:47): abs_dirname(): cd ../Cellar/pyenv/HEAD-986fe1a/bin
++(/usr/local/bin/pyenv:49): abs_dirname(): name=pyenv
+++(/usr/local/bin/pyenv:50): abs_dirname(): resolve_link pyenv
+++(/usr/local/bin/pyenv:36): resolve_link(): /usr/bin/readlink pyenv
++(/usr/local/bin/pyenv:50): abs_dirname(): path=../libexec/pyenv
++(/usr/local/bin/pyenv:44): abs_dirname(): '[' -n ../libexec/pyenv ']'
++(/usr/local/bin/pyenv:45): abs_dirname(): cd_path=../libexec
++(/usr/local/bin/pyenv:46): abs_dirname(): [[ ../libexec != ../\l\i\b\e\x\e\c/\p\y\e\n\v ]]
++(/usr/local/bin/pyenv:47): abs_dirname(): cd ../libexec
++(/usr/local/bin/pyenv:49): abs_dirname(): name=pyenv
+++(/usr/local/bin/pyenv:50): abs_dirname(): resolve_link pyenv
+++(/usr/local/bin/pyenv:36): resolve_link(): /usr/bin/readlink pyenv
+++(/usr/local/bin/pyenv:50): abs_dirname(): true
++(/usr/local/bin/pyenv:50): abs_dirname(): path=
++(/usr/local/bin/pyenv:44): abs_dirname(): '[' -n '' ']'
++(/usr/local/bin/pyenv:53): abs_dirname(): echo /usr/local/Cellar/pyenv/HEAD-986fe1a/libexec
+(/usr/local/bin/pyenv:79): bin_path=/usr/local/Cellar/pyenv/HEAD-986fe1a/libexec
+(/usr/local/bin/pyenv:80): for plugin_bin in '"${bin_path%/}"/plugins//bin'
+(/usr/local/bin/pyenv:81): PATH=/usr/local/Cellar/pyenv/HEAD-986fe1a/plugins/python-build/bin:./bin:./node_modules/.bin:/usr/local/Cellar/pyenv-virtualenv/HEAD-cc9d5f1/shims:/Users/edgar.pellizzon/.rbenv/bin:/usr/local/Cellar/pyenv-virtualenv/HEAD-cc9d5f1/shims:/Users/edgar.pellizzon/.pyenv/shims:/Users/edgar.pellizzon/.pyenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin/brew:/usr/local/sbin
+(/usr/local/bin/pyenv:85): '[' /usr/local/Cellar/pyenv/HEAD-986fe1a '!=' /Users/edgar.pellizzon/.pyenv ']'
+(/usr/local/bin/pyenv:86): for plugin_bin in '"${PYENV_ROOT}"/plugins/*/bin'
+(/usr/local/bin/pyenv:87): PATH=/Users/edgar.pellizzon/.pyenv/plugins/pyenv-doctor/bin:/usr/local/Cellar/pyenv/HEAD-986fe1a/plugins/python-build/bin:./bin:./node_modules/.bin:/usr/local/Cellar/pyenv-virtualenv/HEAD-cc9d5f1/shims:/Users/edgar.pellizzon/.rbenv/bin:/usr/local/Cellar/pyenv-virtualenv/HEAD-cc9d5f1/shims:/Users/edgar.pellizzon/.pyenv/shims:/Users/edgar.pellizzon/.pyenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin/brew:/usr/local/sbin
+(/usr/local/bin/pyenv:90): export PATH=/usr/local/Cellar/pyenv/HEAD-986fe1a/libexec:/Users/edgar.pellizzon/.pyenv/plugins/pyenv-doctor/bin:/usr/local/Cellar/pyenv/HEAD-986fe1a/plugins/python-build/bin:./bin:./node_modules/.bin:/usr/local/Cellar/pyenv-virtualenv/HEAD-cc9d5f1/shims:/Users/edgar.pellizzon/.rbenv/bin:/usr/local/Cellar/pyenv-virtualenv/HEAD-cc9d5f1/shims:/Users/edgar.pellizzon/.pyenv/shims:/Users/edgar.pellizzon/.pyenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin/brew:/usr/local/sbin
+(/usr/local/bin/pyenv:90): PATH=/usr/local/Cellar/pyenv/HEAD-986fe1a/libexec:/Users/edgar.pellizzon/.pyenv/plugins/pyenv-doctor/bin:/usr/local/Cellar/pyenv/HEAD-986fe1a/plugins/python-build/bin:./bin:./node_modules/.bin:/usr/local/Cellar/pyenv-virtualenv/HEAD-cc9d5f1/shims:/Users/edgar.pellizzon/.rbenv/bin:/usr/local/Cellar/pyenv-virtualenv/HEAD-cc9d5f1/shims:/Users/edgar.pellizzon/.pyenv/shims:/Users/edgar.pellizzon/.pyenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin/brew:/usr/local/sbin
+(/usr/local/bin/pyenv:92): PYENV_HOOK_PATH=:/Users/edgar.pellizzon/.pyenv/pyenv.d
+(/usr/local/bin/pyenv:93): '[' /usr/local/Cellar/pyenv/HEAD-986fe1a '!=' /Users/edgar.pellizzon/.pyenv ']'
+(/usr/local/bin/pyenv:95): PYENV_HOOK_PATH=:/Users/edgar.pellizzon/.pyenv/pyenv.d:/usr/local/Cellar/pyenv/HEAD-986fe1a/pyenv.d
+(/usr/local/bin/pyenv:97): PYENV_HOOK_PATH=:/Users/edgar.pellizzon/.pyenv/pyenv.d:/usr/local/Cellar/pyenv/HEAD-986fe1a/pyenv.d:/usr/local/etc/pyenv.d:/etc/pyenv.d:/usr/lib/pyenv/hooks
+(/usr/local/bin/pyenv:101): PYENV_HOOK_PATH=/Users/edgar.pellizzon/.pyenv/pyenv.d:/usr/local/Cellar/pyenv/HEAD-986fe1a/pyenv.d:/usr/local/etc/pyenv.d:/etc/pyenv.d:/usr/lib/pyenv/hooks
+(/usr/local/bin/pyenv:102): export PYENV_HOOK_PATH
+(/usr/local/bin/pyenv:104): shopt -u nullglob
+(/usr/local/bin/pyenv:107): command=-v
+(/usr/local/bin/pyenv:108): case "$command" in
+(/usr/local/bin/pyenv:115): exec pyenv---version
+(/usr/local/Cellar/pyenv/HEAD-986fe1a/libexec/pyenv---version:15): version=2.2.5
+(/usr/local/Cellar/pyenv/HEAD-986fe1a/libexec/pyenv---version:16): git_revision=
+(/usr/local/Cellar/pyenv/HEAD-986fe1a/libexec/pyenv---version:18): cd /usr/local/Cellar/pyenv/HEAD-986fe1a/libexec
+(/usr/local/Cellar/pyenv/HEAD-986fe1a/libexec/pyenv---version:18): git remote -v
+(/usr/local/Cellar/pyenv/HEAD-986fe1a/libexec/pyenv---version:18): grep -q pyenv
+(/usr/local/Cellar/pyenv/HEAD-986fe1a/libexec/pyenv---version:23): echo 'pyenv 2.2.5'
pyenv 2.2.5
2

There are 2 answers

0
Edgar Pellizzon On

This might not be the ultimate answer, but I was able to overcome this issue with a patch. Source here

So, basically, we clone a repository from the python version we want to install, in this case, 3.9.6:

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

Go to directory

cd cpython

And for this part, we make the following changes on configure file.

diff --git configure configure
index e39c16eee2..2455870bf8 100755
--- configure
+++ configure
@@ -5202,10 +5202,6 @@ $as_echo "$as_me:
   " >&6;}
 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; }
 cat >> conftest.c <<EOF
@@ -5334,6 +5330,10 @@ $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
@@ -9230,6 +9230,9 @@ fi
        ppc)
            MACOSX_DEFAULT_ARCH="ppc64"
            ;;
+       arm64)
+           MACOSX_DEFAULT_ARCH="arm64"
+           ;;
        *)
            as_fn_error $? "Unexpected output of 'arch' on OSX" "$LINENO" 5
            ;;

The interesting part here is that I had to save configure before throwing changes in the patch

git diff > python-3.9.6-m1.patch

And then had to undo the changes on configure, and save it again (all of this without committing to branch).

After that,

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

This was the only way I got to install version 3.9.6 with pyenv on a mac m1 Monterey 12.3, with Rosetta 2.

0
Amin Adha On

This worked for me on Monterey 12.6

cd ~/.pyenv/plugins/python-build && git pull

Please refer https://github.com/pyenv/pyenv/wiki/Common-build-problems