9

I was trying to install numpy version 1.22.3 on a M1 Macbook with pip3, and pip3 says the package is present, but when I try to import the module, an error gets thrown at me that says
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.
The full text of the error is:
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)

I followed the link to the troubleshooting documentation provided, and none of the solutions worked.
I've tried reinstalling both pip3 and Python, and that didn't work either.

Any ideas?

Lilly Pernichele
  • 91
  • 1
  • 1
  • 3
  • 1
    Sounds like the python interprerer would be x86_64 and not arm64 version, how did you install it? – Sami Kuhmonen Apr 05 '22 at 03:06
  • @SamiKuhmonen I installed it off of the [Python Website's MacOS downloads page](https://www.python.org/downloads/macos/) – Lilly Pernichele Apr 05 '22 at 03:15
  • Got the same issue but with `black` package installed using pip (python 3.10). Any ideas on how to solve this issue? – Mike Apr 30 '22 at 08:45

3 Answers3

5

I was able to fix this issue by uninstalling and reinstalling numpy in my virtual environment.

DharmanBot
  • 1,066
  • 2
  • 6
  • 10
822_BA
  • 98
  • 1
  • 7
2

If none of above worked for you try this way of install numpy after remove it pip uninstall numpy

arm64 installtion

arch -arm64 pip install numpy

x86_64 installtion

arch -x86_64 pip install numpy

or you can keep an alise for that in your bash config file:

alias pip86='arch -x86_64 pip install'
alias pip_arm='arch -arm64 pip install'
A. Sharif
  • 31
  • 1
1

I had the same issue. What worked for me was to downgrade the python version from 3.10 to 3.8 and then reinstall numpy.

Ionut
  • 11
  • 1