Skip to content

Python build fails on M1 Apple Silicon with arm64 homebrew #1768

@rjmoggach

Description

@rjmoggach

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions