You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

macOS Ventura M1环境下Poetry安装numpy==1.21.1失败求助

解决M1 Pro设备上Poetry安装numpy==1.21.1失败的问题

问题背景

本地环境:Python 3.9.6,pip3 22.3.1,Poetry 1.3.1,2021款MacBook Pro(M1 Pro,macOS Ventura),执行poetry install时因poetry.lock要求安装numpy==1.21.1失败,已尝试brew install numpy和pip3 install numpy==1.21.1均无效。

核心原因

M1系列芯片为ARM架构,numpy 1.21.1无官方适配ARM的预编译轮子(wheel),直接安装会触发源码编译,而编译所需的环境配置未到位,导致安装失败。

解决方案

1. 用Rosetta 2模拟x86架构安装

打开终端,通过Rosetta 2启动新会话:

arch -x86_64 zsh

在该会话内执行Poetry安装命令:

poetry install

此方法通过模拟x86架构调用对应预编译轮子,绕过ARM编译问题

2. 配置Poetry适配ARM环境的依赖规则

编辑项目的pyproject.toml,在[tool.poetry.dependencies]下修改numpy配置:

numpy = "~=1.21.1; platform_machine == 'arm64'"

更新锁文件并重新安装:

poetry lock --no-update
poetry install

3. 安装编译依赖后原生编译

若需ARM原生编译,先安装编译依赖:

brew install openblas

设置环境变量指定编译依赖路径:

export OPENBLAS=$(brew --prefix openblas)
export CFLAGS="-falign-functions=8 ${CFLAGS}"

再执行Poetry安装:

poetry install

4. 升级Poetry并清理缓存

旧版本Poetry可能存在ARM环境依赖解析问题,先升级Poetry:

curl -sSL https://install.python-poetry.org | python3 -

清理Poetry的PyPI缓存:

poetry cache clear --all pypi

最后重新执行安装:

poetry install

内容的提问来源于stack exchange,提问作者Anchen Huang

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 07:30:49