(mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))
Asked Answered
P

7

18

I have a problem when I run a .py file on a Macbook Air M1:

[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

I think the reason is that I'm using the numpy package for 'x86_64', so I tried to use pip install numpy --upgrade to upgrade numpy, but I got output like:

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

I also tried python3 -m pip install --upgrade pip to upgrade python, but still;

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

Can anyone help me?

Pyrargyrite answered 9/7, 2022 at 10:19 Comment(0)
P
-4

I solved the problem by simply uninstalling numpy package:

pip3 uninstall numpy

and reinstalling it:

pip3 install numpy
Pyrargyrite answered 9/7, 2022 at 11:5 Comment(2)
what does file command say about that shared object now? does it support both architecturesFelonious
This does not help. This is more of an architecture issue.Kaleena
S
18

This worked for me -

ARCHFLAGS="-arch arm64" pip install numpy  --compile --no-cache-dir
Scandinavian answered 19/12, 2022 at 8:32 Comment(0)
B
8

For my Mac M1 processor best variant of installation is the command

pip3 install numpy==1.24.0  --compile --force-reinstall
Backsword answered 22/5, 2023 at 8:9 Comment(3)
Great solution. It solved my issue with pydantic on my M1 Max.Tadd
Oh, the --compile prefix successfully installs absolutely all modules for OSX.Solfatara
Same situation about PyObjC which was incompatible to my OSX version.Solfatara
P
1

I had this issue in pycharm executing tests.

The problem was the interpreter for the test case was set to the wrong one.

Going to edit configurations for the test case fixed it.

Praedial answered 22/5, 2023 at 7:44 Comment(0)
A
0

I had this issue and after uninstalling and reinstalling didn't work, I updated to Python 3.11 and it works perfectly now.

Alonaalone answered 29/1, 2023 at 23:9 Comment(0)
E
0

Run your python file or package with arm64.

Example

arch -arm64 app-store-connect
Enterovirus answered 31/5 at 13:6 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Bidwell
S
0

I faced the same error. Just uninstalled and reinstalled the corresponding libraries in the venv and the issue got resolved.

Example -

Error - tried: '/Users/xxxxx/.local/share/virtualenvs/yyyyyy-ken6_ahQ/lib/python3.12/site-packages/numpy/core/_multiarray_umath.cpython-312-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))

pip3 uninstall numpy

pip3 install numpy

If any version related error is given, install the version that is suggested in the error message

pip3 install numpy==<version_number>
Senescent answered 10/7 at 5:53 Comment(0)
P
-4

I solved the problem by simply uninstalling numpy package:

pip3 uninstall numpy

and reinstalling it:

pip3 install numpy
Pyrargyrite answered 9/7, 2022 at 11:5 Comment(2)
what does file command say about that shared object now? does it support both architecturesFelonious
This does not help. This is more of an architecture issue.Kaleena

© 2022 - 2024 — McMap. All rights reserved.