/usr/local/bin/brew # x86
/opt/homebrew/bin/brew # arm
目前支持rosetta的终端是iterm,可以直接勾选
安装Homebrew
安装pyenv
安装python3.6
确认python3.6是x86版本
代码
1
2
3
4
5
6
7
Python 3.6.15 (default, Oct 30 2024, 01:16:00)
[GCC Apple LLVM 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> print(platform.machine())
x86_64
>>>
#Install Rosetta/usr/sbin/softwareupdate--install-rosetta--agree-to-license# Install x86_64 brewarch-x86_64/bin/bash-c"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"# Set up x86_64 homebrew and pyenv and temporarily set aliasesaliasbrew86="arch -x86_64 /usr/local/bin/brew"aliaspyenv86="arch -x86_64 pyenv"# Install required packages and flags for building this particular python version through emulationbrew86installpyenvgcclibffigettext# -------------- change to openssl@1.1 here and others as well ----------+# ↓exportCPPFLAGS="-I$(brew86 --prefix libffi)/include -I$(brew86 --prefix openssl@1.1)/include -I$(brew86 --prefix readline)/lib"exportCFLAGS="-I$(brew86 --prefix openssl@1.1)/include -I$(brew86 --prefix bzip2)/include -I$(brew86 --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include -Wno-implicit-function-declaration"exportLDFLAGS="-L$(brew86 --prefix openssl@1.1)/lib -L$(brew86 --prefix readline)/lib -L$(brew86 --prefix zlib)/lib -L$(brew86 --prefix bzip2)/lib -L$(brew86 --prefix gettext)/lib -L$(brew86 --prefix libffi)/lib"# Providing an incorrect openssl version forces a proper openssl version to be downloaded and linked during the buildexportPYTHON_BUILD_HOMEBREW_OPENSSL_FORMULA=openssl@1.1# Install Python 3.6pyenv86install--patch3.6.15<<(curl-sSLhttps://raw.githubusercontent.com/pyenv/pyenv/master/plugins/python-build/share/python-build/patches/3.6.15/Python-3.6.15/0008-bpo-45405-Prevent-internal-configure-error-when-runn.patch\?full_index\=1)