python - (mach-o 文件,但它是一个不兼容的架构(有 'arm64' ,需要 'x86_64' ))

标签 python macos x86 importerror apple-silicon

我在 Macbook Air M1 上运行 .py 文件时遇到问题:

[Running] python3 -u "/Users/kaiyuwei/Documents/graduation project/metaheuristics/run_CRO.py"
Traceback (most recent call last):
  File "/Users/kaiyuwei/Library/Python/3.8/lib/python/site-packages/numpy/core/__init__.py", line 23, in <module>
    from . import multiarray
  File "/Users/kaiyuwei/Library/Python/3.8/lib/python/site-packages/numpy/core/multiarray.py", line 10, in <module>
    from . import overrides
  File "/Users/kaiyuwei/Library/Python/3.8/lib/python/site-packages/numpy/core/overrides.py", line 6, in <module>
    from numpy.core._multiarray_umath import (
ImportError: dlopen(/Users/kaiyuwei/Library/Python/3.8/lib/python/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so, 0x0002): tried: '/Users/kaiyuwei/Library/Python/3.8/lib/python/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/kaiyuwei/Documents/graduation project/metaheuristics/run_CRO.py", line 1, in <module>
    from models.multiple_solution.evolutionary_based.CRO import BaseCRO
  File "/Users/kaiyuwei/Documents/graduation project/metaheuristics/models/multiple_solution/evolutionary_based/CRO.py", line 1, in <module>
    import numpy as np
  File "/Users/kaiyuwei/Library/Python/3.8/lib/python/site-packages/numpy/__init__.py", line 140, in <module>
    from . import core
  File "/Users/kaiyuwei/Library/Python/3.8/lib/python/site-packages/numpy/core/__init__.py", line 49, in <module>
    raise ImportError(msg)
ImportError: 

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

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.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.8 from "/Library/Developer/CommandLineTools/usr/bin/python3"
  * The NumPy version is: "1.23.1"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: dlopen(/Users/kaiyuwei/Library/Python/3.8/lib/python/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so, 0x0002): tried: '/Users/kaiyuwei/Library/Python/3.8/lib/python/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))


[Done] exited with code=1 in 0.055 seconds

我认为原因是我正在为'x86_64'使用numpy包,所以我尝试使用pip install numpy --upgrade来升级numpy,但我得到了这样的输出:

Requirement already satisfied: numpy in /Users/kaiyuwei/Library/Python/3.8/lib/python/site-packages (1.23.1)

我也试过 python3 -m pip install --upgrade pip 来升级 python,但还是;

Requirement already satisfied: pip in /Users/kaiyuwei/Library/Python/3.8/lib/python/site-packages (22.1.2)

谁能帮帮我?

最佳答案

我通过简单地卸载 numpy 包解决了这个问题:

pip3 uninstall numpy

并重新安装它:

pip3 install numpy

关于python - (mach-o 文件,但它是一个不兼容的架构(有 'arm64' ,需要 'x86_64' )),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72920577/

相关文章:

macos - 什么会导致 .NET Core 二进制文件加载 native 库,然后抛出 DllNotFoundException?

assembly - 双缓冲,汇编 x86

assembly - 组装中的 EBP、ESP 和堆栈框架

assembly - 跳入保护模式时出现三重故障

python - Keras 中的有状态 LSTM 中一批样本之间的状态是否保留?

python - 是否有用于查询嵌套 jsonfield 键的 django-orm 查找?

node.js - Brew 安装后 Node 使用错误版本

macos - 无法将分支推送到 github "Use git@github.com:Paratron/spacebattles.git"

python - 如何在 Python 中将 'X' 的字符串填充到最小长度?

python - pandas from mac ports ImportError : No module named io. 数据