在使用网上提到的brew和pyenv安装的时候,我的电脑总会报BUILD FAILED错误。
找了一天才找到解决办法,真的十分痛苦,特此记录一下,让别的小伙伴也不再迷茫。
解决办法参考网址:click here(需要VPN)
切记,在安装完brew时,要更换brew源,否则安装其他package会很慢。
更换brew源参考网址:click here
没有VPN的话,可以参考下面:
- Install Rosetta
/usr/sbin/softwareupdate --install-rosetta --agree-to-license
如果这里报 Rosetta 2 is not supported 的bug,请前往应用程序搜索 终端.app,然后把 使用Rosetta打开 保持关闭
。
- Install x86_64 brew
之前报BUILD FAILED错误,主要原因应该是arm架构的问题,所以这里我们底层使用x86架构,Rosetta相当于arm和x86之间的转换桥梁。(个人理解,如若不妥,欢迎指正)
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
- 更换brew源
参考网址:click here
我使用的是清华源:
- 替换brew.git
cd "$(brew --repo)"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
- 替换homebrew-core.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
- 刷新源
brew update
- Set up x86_64 homebrew and pyenv and temporarily set aliases
给x86_64 brew和pyenv起别名,随便你自己怎么起。
alias ibrew="arch -x86_64 /usr/local/bin/brew"
alias ipyenv="arch -x86_64 pyenv"
- Install required packages and flags for building this particular python version through emulation
ibrew install pyenv gcc libffi gettext
export CPPFLAGS="-I$(ibrew --prefix libffi)/include -I$(ibrew --prefix openssl)/include -I$(ibrew --prefix readline)/lib"
export CFLAGS="-I$(ibrew --prefix openssl)/include -I$(ibrew --prefix bzip2)/include -I$(ibrew --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include -Wno-implicit-function-declaration"
export LDFLAGS="-L$(ibrew --prefix openssl)/lib -L$(ibrew --prefix readline)/lib -L$(ibrew --prefix zlib)/lib -L$(ibrew --prefix bzip2)/lib -L$(ibrew --prefix gettext)/lib -L$(ibrew --prefix libffi)/lib"
- Providing an incorrect openssl version forces a proper openssl version to be downloaded and linked during the build
export PYTHON_BUILD_HOMEBREW_OPENSSL_FORMULA=openssl@1.0
- Install Python 3.6
ipyenv install --patch 3.6.15 <<(curl -sSL https://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)