Python: How to solve the numpy ImportError on Apple Silicon?
Asked Answered
G

2

4

I installed my python virtual environment on m1 AppleSilicon through miniforge3.

after execute conda -create py39 numpy matplotlib pandas python=3.9

I checked through conda list, numpy package had installed.

But when I did import numpy as np the ImportError happened.

like this

ImportError                               Traceback (most recent call last)
~/miniforge3/lib/python3.9/site-packages/numpy/core/__init__.py in <module>
     21 try:
---> 22     from . import multiarray
     23 except ImportError as exc:

~/miniforge3/lib/python3.9/site-packages/numpy/core/multiarray.py in <module>
     11 
---> 12 from . import overrides
     13 from . import _multiarray_umath

~/miniforge3/lib/python3.9/site-packages/numpy/core/overrides.py in <module>
      6 
----> 7 from numpy.core._multiarray_umath import (
      8     add_docstring, implement_array_function, _get_implementing_args)

ImportError: dlopen(/Users/frank_qin/miniforge3/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so, 0x0002): Library not loaded: @rpath/libcblas.3.dylib
  Referenced from: /Users/frank_qin/miniforge3/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so
  Reason: tried: '/Users/frank_qin/miniforge3/lib/libcblas.3.dylib' (no such file), '/Users/frank_qin/miniforge3/lib/libcblas.3.dylib' (no such file), '/Users/frank_qin/miniforge3/lib/python3.9/site-packages/numpy/core/../../../../libcblas.3.dylib' (no such file), '/Users/frank_qin/miniforge3/lib/libcblas.3.dylib' (no such file), '/Users/frank_qin/miniforge3/lib/libcblas.3.dylib' (no such file), '/Users/frank_qin/miniforge3/lib/python3.9/site-packages/numpy/core/../../../../libcblas.3.dylib' (no such file), '/Users/frank_qin/miniforge3/lib/libcblas.3.dylib' (no such file), '/Users/frank_qin/miniforge3/bin/../lib/libcblas.3.dylib' (no such file), '/Users/frank_qin/miniforge3/lib/libcblas.3.dylib' (no such file), '/Users/frank_qin/miniforge3/bin/../lib/libcblas.3.dylib' (no such file), '/usr/local/lib/libcblas.3.dylib' (no such file), '/usr/lib/libcblas.3.dylib' (no such file)

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
/var/folders/yk/7dwhc7352g3fm0rp04d22qmw0000gn/T/ipykernel_52010/3593848235.py in <module>
----> 1 import numpy as np

~/miniforge3/lib/python3.9/site-packages/numpy/__init__.py in <module>
    148     from . import _distributor_init
    149 
--> 150     from . import core
    151     from .core import *
    152     from . import compat

~/miniforge3/lib/python3.9/site-packages/numpy/core/__init__.py in <module>
     46 """ % (sys.version_info[0], sys.version_info[1], sys.executable,
     47         __version__, exc)
---> 48     raise ImportError(msg)
     49 finally:
     50     for envkey in env_added:

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.9 from "/Users/frank_qin/miniforge3/bin/python"
  * The NumPy version is: "1.21.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/frank_qin/miniforge3/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so, 0x0002): Library not loaded: @rpath/libcblas.3.dylib
  Referenced from: /Users/frank_qin/miniforge3/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so
  Reason: tried: '/Users/frank_qin/miniforge3/lib/libcblas.3.dylib' (no such file), '/Users/frank_qin/miniforge3/lib/libcblas.3.dylib' (no such file), '/Users/frank_qin/miniforge3/lib/python3.9/site-packages/numpy/core/../../../../libcblas.3.dylib' (no such file), '/Users/frank_qin/miniforge3/lib/libcblas.3.dylib' (no such file), '/Users/frank_qin/miniforge3/lib/libcblas.3.dylib' (no such file), '/Users/frank_qin/miniforge3/lib/python3.9/site-packages/numpy/core/../../../../libcblas.3.dylib' (no such file), '/Users/frank_qin/miniforge3/lib/libcblas.3.dylib' (no such file), '/Users/frank_qin/miniforge3/bin/../lib/libcblas.3.dylib' (no such file), '/Users/frank_qin/miniforge3/lib/libcblas.3.dylib' (no such file), '/Users/frank_qin/miniforge3/bin/../lib/libcblas.3.dylib' (no such file), '/usr/local/lib/libcblas.3.dylib' (no such file), '/usr/lib/libcblas.3.dylib' (no such file)

Please tell me how to solve this Error!

Glutelin answered 6/12, 2021 at 7:20 Comment(1)
This looks like an issue with the numpy package from your distribution. I don't know anything about mini-forge, so I can't help with that specifically, but if it's part of a larger toolset, you might want to add a tag for that (the mini-forge tag you have now doesn't seem widely used).Displode
O
9

You may refer to this issue: https://github.com/numpy/numpy/issues/12970.

In short, you can try to install openblas by

conda install openblas

This solves my problem.

Ohaus answered 8/12, 2021 at 16:24 Comment(1)
tried so many things but this one liner is the only method that worked. Thanks so muchFloppy
K
6

The following sequence of commands worked for me:

conda clean --all
conda install openblas
----
conda uninstall numpy
conda install numpy
Keenakeenan answered 25/5, 2022 at 17:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.