在 Python 版本 3.10 上使用 pip3 在 M1 Mac 上安装 numpy 时出现"incompatible architecture (have 'arm64', need '



我试图在带有pip3的M1 Macbook上安装numpy版本1.22.3,pip3表示包存在,但当我尝试导入模块时,出现了一个错误,显示
Importing the numpy C-extensions failed. This error can happen for

many reasons, often due to issues with your setup or how NumPy was

installed.
错误的全文为:
dlopen(/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/_multiarray_umath.cpython-

310-darwin.so, 0x0002): tried: '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/_multiarray_umath.cpy

thon-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/usr/lib/_multiarray_umath.cpython-310-da

rwin.so' (no such file)

我按照提供的故障排除文档的链接进行操作,但没有一个解决方案起作用
我尝试过重新安装pip3和Python,但都没有成功。

有什么想法吗?

我能够通过在虚拟环境中卸载并重新安装numpy来解决这个问题。

如果以上都不适用,请在删除numpy后尝试这种安装方式pip uninstall numpy

arm64安装

arch -arm64 pip install numpy

x86_64安装

arch -x86_64 pip install numpy

或者你可以在你的bash配置文件中保存一个alise:

alias pip86='arch -x86_64 pip install'
alias pip_arm='arch -arm64 pip install'

我遇到了同样的问题。对我来说有效的是将python版本从3.10降级到3.8,然后重新安装numpy。

最新更新