MAC M1使用Rosetta安装python3.6

文章讲述了在Mac电脑上使用brew和pyenv安装时遇到BUILDFAILED问题的解决方法,包括安装Rosetta,更换brew源至清华大学源,以及针对arm架构问题采用x86_64安装,并详细提供了安装和配置步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在使用网上提到的brew和pyenv安装的时候,我的电脑总会报BUILD FAILED错误。

找了一天才找到解决办法,真的十分痛苦,特此记录一下,让别的小伙伴也不再迷茫。

解决办法参考网址:click here(需要VPN)
切记,在安装完brew时,要更换brew源,否则安装其他package会很慢。
更换brew源参考网址:click here


没有VPN的话,可以参考下面:

  1. Install Rosetta
/usr/sbin/softwareupdate --install-rosetta --agree-to-license

如果这里报 Rosetta 2 is not supported 的bug,请前往应用程序搜索 终端.app,然后把 使用Rosetta打开 保持关闭

在这里插入图片描述

  1. 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)"
  1. 更换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
  1. 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"
  1. 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"
  1. 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
  1. 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)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

柳叶lhy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值