Repository navigation
Python build fails on M1 Apple Silicon with arm64 homebrew #1768
Copy link
Copy link
Closed
Description
Referencing other issues, I've been trying unsuccessfully for a native compile of 3.9.0 on an M1 MacBook Air using the following:
(FYI rosetta works without any issue with this config - goal is to compile both)
.zshrc
# PYENV
ARCH=`arch`
if [[ "${ARCH}" == "arm64" ]]; then
export PYENV_ROOT="/Users/rob/.pyenv/arm64"
else
export PYENV_ROOT="/Users/rob/.pyenv/rosetta"
fi
PYENV_BIN="$PYENV_ROOT/bin"
export PYENV_SHELL=zsh
# export PYENV_ROOT=$(pyenv root)
# export PYENV_VERSION=$(pyenv version-name)
export PYTHONPATH=$PYENV_ROOT/shims
SDK_PATH="$(xcrun --show-sdk-path)"
export CPATH="${SDK_PATH}/usr/include"
export CFLAGS="-I${SDK_PATH}/usr/include/sasl $CFLAGS"
export CFLAGS="-I${SDK_PATH}/usr/include $CFLAGS"
export LDFLAGS="-L${SDK_PATH}/usr/lib $LDFLAGS"
if [[ "${ARCH}" == "arm64" ]]; then
PREFIX="/opt/homebrew/opt"
else
PREFIX="/usr/local/opt"
fi
ZLIB="${PREFIX}/zlib"
BZIP2="${PREFIX}/bzip2"
READLINE="${PREFIX}/readline"
SQLITE="${PREFIX}/sqlite"
OPENSSL="${PREFIX}/openssl@1.1"
TCLTK="${PREFIX}/tcl-tk"
PGSQL="${PREFIX}/postgresql@10"
LIBS=('ZLIB' 'BZIP2' 'READLINE' 'SQLITE' 'OPENSSL' 'PGSQL' 'TCLTK')
for LIB in $LIBS; do
BINDIR="${(P)LIB}/bin"
if [ -d "${BINDIR}" ]; then
export PATH="${BINDIR}:$PATH"
fi
LIBDIR="${(P)LIB}/lib"
if [ -d "${LIBDIR}" ]; then
export LDFLAGS="-L${LIBDIR} $LDFLAGS"
export DYLD_LIBRARY_PATH="${LIBDIR}:$DYLD_LIBRARY_PATH"
PKGCFGDIR="${LIBDIR}/pkgconfig"
if [ -d "${PKGCFGDIR}" ]; then
export PKG_CONFIG_PATH="${PKGCFGDIR} $PKG_CONFIG_PATH"
fi
fi
INCDIR="${(P)LIB}/include"
if [ -d "${INCDIR}" ]; then
export CFLAGS="-I${INCDIR} $CFLAGS"
fi
done
export CPPFLAGS="${CFLAGS}"
export CXXFLAGS="${CFLAGS}"
export PYTHON_CONFIGURE_OPTS="--enable-framework"
export PYTHON_CONFIGURE_OPTS="--with-openssl=$(brew --prefix openssl) ${PYTHON_CONFIGURE_OPTS}"
export PYTHON_CONFIGURE_OPTS="--with-tcltk-includes='-I$(brew --prefix tcl-tk)/include' ${PYTHON_CONFIGURE_OPTS}"
export PYTHON_CONFIGURE_OPTS="--with-tcltk-libs='-L$(brew --prefix tcl-tk)/lib -ltcl8.6 -ltk8.6' ${PYTHON_CONFIGURE_OPTS}"
eval "$(pyenv init -)"
# eval "$(pyenv virtualenv-init -)"
Result:
Here's the relevant output from pyenv install 3.8.6:
configure: error: Unexpected output of 'arch' on OSX
Environment
> env|grep 'FLAGS\|PATH'
PATH=/Users/rob/.pyenv/arm64/shims:/opt/homebrew/opt/tcl-tk/bin:/opt/homebrew/opt/openssl@1.1/bin:/opt/homebrew/opt/sqlite/bin:/opt/homebrew/opt/bzip2/bin:/Users/rob/bin:/Users/rob/.pyenv/arm64/bin:/Applications/Sublime Text.app/Contents/SharedSupport/bin:/Users/rob/bin:/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin
PYTHONPATH=/Users/rob/.pyenv/arm64/shims
CPATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
CFLAGS=-I/opt/homebrew/opt/tcl-tk/include -I/opt/homebrew/opt/openssl@1.1/include -I/opt/homebrew/opt/sqlite/include -I/opt/homebrew/opt/readline/include -I/opt/homebrew/opt/bzip2/include -I/opt/homebrew/opt/zlib/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sasl
LDFLAGS=-L/opt/homebrew/opt/tcl-tk/lib -L/opt/homebrew/opt/openssl@1.1/lib -L/opt/homebrew/opt/sqlite/lib -L/opt/homebrew/opt/readline/lib -L/opt/homebrew/opt/bzip2/lib -L/opt/homebrew/opt/zlib/lib -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib
PKG_CONFIG_PATH=/opt/homebrew/opt/tcl-tk/lib/pkgconfig /opt/homebrew/opt/openssl@1.1/lib/pkgconfig /opt/homebrew/opt/sqlite/lib/pkgconfig /opt/homebrew/opt/readline/lib/pkgconfig /opt/homebrew/opt/zlib/lib/pkgconfig
CPPFLAGS=-I/opt/homebrew/opt/tcl-tk/include -I/opt/homebrew/opt/openssl@1.1/include -I/opt/homebrew/opt/sqlite/include -I/opt/homebrew/opt/readline/include -I/opt/homebrew/opt/bzip2/include -I/opt/homebrew/opt/zlib/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sasl
CXXFLAGS=-I/opt/homebrew/opt/tcl-tk/include -I/opt/homebrew/opt/openssl@1.1/include -I/opt/homebrew/opt/sqlite/include -I/opt/homebrew/opt/readline/include -I/opt/homebrew/opt/bzip2/include -I/opt/homebrew/opt/zlib/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sasl```
I know this is related to the compiler not recognizing `arm64` as architecture however the patches I've found don't solve the problem.Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
rjmoggach commentedon Jan 4, 2021
It seems I was able to get 3.8.6 installed using a patch I found on a plone site - the ones in other issues here didn't work for me... Here's the code in question:
pyenv install --patch 3.8.6 <<(curl -sSL https://raw.githubusercontent.com/Homebrew/formula-patches/113aa84/python/3.8.3.patch\?full_index\=1)That's a 3.8.3 patch but clearly it's not different enough to to affect 3.8.6. This does NOT work for 3.9.0 which is the next task.
rjmoggach commentedon Jan 4, 2021
Here's the relevant patches in the homebrew formula-patches repo:
https://github.com/Homebrew/formula-patches/tree/master/python
anton-petrov commentedon Jan 4, 2021
EDITED 11/01/2021:
Python 3.9.1 compiles successfully with native homebrew, and latest pyenv installed from github or homebrew packages.
cclauss commentedon Jan 4, 2021
Can we please get a release of pyenv that includes Python 3.9.1?
It is the first CPython that defaults to 64-bit on Windows and natively supports Apple Silicon ARM CPUs.
bengartner commentedon Jan 4, 2021
There is an open ticket for this: #1760
rjmoggach commentedon Jan 4, 2021
@anton-petrov are you saying you had success by installing pyenv from github directly NOT via homebrew?
anton-petrov commentedon Jan 4, 2021
Yes, directly from GitHub, that's right.
anton-petrov commentedon Jan 4, 2021
It seems like it's time to give the rights to someone else, so the code changes quickly get into the main branch...
sinwoobang commentedon Jan 7, 2021
Same problem here.
sinwoobang commentedon Jan 9, 2021
I uninstalled native pyenv and am using only Rosetta-based pyenv.
This is something temporary but got rid of every stress of mine.
mariusnita commentedon Jan 10, 2021
I just cloned pyenv and
pyenv install 3.9.1fails on M1 MacBook Air with this output:If I go into the build directory, I can build it successfully by configuring it like this:
I can't tell where the root issue is but there is a discrepancy between Python assuming
aarch64and the system reportingarm64.cclauss commentedon Jan 10, 2021
@mariusnita OpenSSL v1.1.1 on M1 discussed in #1744
mariusnita commentedon Jan 10, 2021
@cclauss My issue was actually related to using GNU coreutils from brew. When I removed GNU coreutils from my $PATH, Python built fine with the builtin macOS tools.
cclauss commentedon Jan 27, 2021
Is this issue fixed in the current release? https://github.com/pyenv/pyenv/releases
neilpanchal commentedon Jan 30, 2021
I am getting similar but not exact errors on Apple Silicon:
70 remaining items
dontirun commentedon Apr 21, 2022
I successfully installed Python
3.6on an Apple M1 MacBook Pro running Monterey using the following setup. There is probably some things in here that can be removed/refined... but it worked for me!Note, the build succeeds but gives the following warning
running
pyenv versionsshows that3.6.15can be used normally by the systemAnveshrithaa commentedon Apr 22, 2022
Thank you so much! It saved my day.
dja-tel commentedon May 5, 2022
Hi @Anveshrithaa and @dontirun
Would you mind checking the following?
1 - Install the snappy library on the system and python@3.6 with brew86
2- Create a virtual environment with the pyton3.6 interpreter.
2- Install in the virtual environment python-snappy==0.5.4 with pip
4- Enter a python console in that environment and try to import snappy
5- try to use a snappy functionality, e.g. -> snappy.compress(file)
Thank you very much
jesseinit commentedon May 6, 2022
I'm getting this error whenever I try to install any python version.
How do I fix it? I'm on Monterey v12.1 on the M1 Pro.
cclauss commentedon May 6, 2022
Is that macOS 12.1 or 12.3?!?
%
sw_versjesseinit commentedon May 7, 2022
ProductName: macOS
ProductVersion: 12.1
BuildVersion: 21C52
cclauss commentedon May 7, 2022
https://stackoverflow.com/questions/71577626/issues-installing-python-3-8-10-on-macos-12-3-monterey
vishal-wadhwa commentedon Jan 2, 2023
Fix for 3.8.7 -
Okay. So within a mix of multiple issues. I was facing the following errors -
pyenv install 3.8.7pyenv install --patch 3.8.7 <<(curl -sSL https://raw.githubusercontent.com/Homebrew/formula-patches/9811be33170a8f31a684fae6955542e31eb4e61e/python/3.8.7.patch)This was despite the fact that I already have the latest pyenv.
Finally, the fix was to apply both the patches like this
Setup: Mac M1 (OS 12.6.2 Monterey)
l0g1c-80m8 commentedon Jan 25, 2023
This alone didn't work for me while I was trying to install
python 3.6.15. I needed to do take the following additional steps before running the final installation command:.zshrcfile so that you can freely usepyenv86without having to alias them every time.After this, I ran the final installation command. There was an error with the installation saying I had a few directories missing:
To address this just install the missing packages in your brew x86 directory using the following command:
You can add or remove the packages as observed from the error message. Finally running the final installation command solved the issue:
cclauss commentedon Jan 25, 2023
@l0g1c-80m8 I would highly recommend that you run pyupgrade on your codebase and make whatever changes are required to run it on a supported version of Python. Python 3.6’s end-of-life was more than a year ago. In that time, all supported versions of Python have received high profile security updates but Python 3.6 and older have not.
There is also the issue that Python 3.9.1 was the first release to support Apple Silicon so while earlier versions may work, this is not supported by the Python core team. If someone knows of further backporting of this support then I would love to hear about it but it certainly would not cover Python 3.6.
l0g1c-80m8 commentedon Jan 25, 2023
@cclauss appreciate your suggestions and I completely agree with them. In this case however, I need
python 3.6for my assignments as the environment that will run my submissions is runningpython 3.6.omkarsk98 commentedon Feb 2, 2023
Getting error as
Tapudp commentedon Feb 8, 2023
I was facing this issue, while installing Python version 3.9/3.10 on my m1-mac with MacOS Ventura 13.1, and it kept throwing the same error about not being able to find module
_sslfrom OpenSSL. The system already hadbut this one following line from @dontirun 's message worked like a charm! Thank you! 🙇🏻♀️🙇♤
l0g1c-80m8 commentedon Feb 8, 2023
@omkarsk98 Pardon my late response to your issue.
Based on the above comment, it looks like you don't have any OpenSSL module installed or is not exported. I'd recommend installing the version used above and exporting the path and trying the installation again.
Also note that in the original workaround, we export an incorrect OpenSSL version to force the download of the correct version.
Since, you will be doing that manually now, this line will no longer be needed.
mayaracsferreira commentedon Sep 30, 2024
Do you know if is there any patch for Python 3.11, please?