tensorflow / numpy on M1 / Monterey

I'm having trouble installing tensorflow on my M1 (2020 M1 Macbook Pro), running OS 12.1.

I'm following the instructions here. I've attempted several permutations of python version and TF version, but for this run my specific commands are

conda create -n tf_m1 python=3.9
conda activate tf_m1
conda install -c apple tensorflow-deps==2.7.0
python -m pip install tensorflow-macos==2.7.0
python -m pip install tensorflow-metal

No errors so far. Then if I run python and import tensorflow, I get an error (full text below). It seems to boil down to a no-such-file error for '<path/to/env>/lib/libcblas.3.dylib'. That file does exist, but it's a link to libopenblas_vortexp-r0.3.17.dylib, which does not exist.

FWIW, I get the same error if I just try to import numpy. I can get a working numpy install with version 1.20, but not 1.19, which TF appparently requires.

This issue describes a similar error. They resolved it by uninstalling/reinstalling numpy, but that did not work for me. Any ideas?

Here's the full error text.

Python 3.9.7 (default, Sep 16 2021, 23:53:23) 
[Clang 12.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
 File "/Users/jeremy/miniforge3/envs/tf_m1/lib/python3.9/site-packages/numpy/core/__init__.py", line 22, in <module>
  from . import multiarray
 File "/Users/jeremy/miniforge3/envs/tf_m1/lib/python3.9/site-packages/numpy/core/multiarray.py", line 12, in <module>
  from . import overrides
 File "/Users/jeremy/miniforge3/envs/tf_m1/lib/python3.9/site-packages/numpy/core/overrides.py", line 7, in <module>
  from numpy.core._multiarray_umath import (
ImportError: dlopen(/Users/jeremy/miniforge3/envs/tf_m1/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so, 0x0002): Library not loaded: @rpath/libcblas.3.dylib
 Referenced from: /Users/jeremy/miniforge3/envs/tf_m1/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so
 Reason: tried: '/Users/jeremy/miniforge3/envs/tf_m1/lib/libcblas.3.dylib' (no such file), '/Users/jeremy/miniforge3/envs/tf_m1/lib/libcblas.3.dylib' (no such file), '/Users/jeremy/miniforge3/envs/tf_m1/lib/python3.9/site-packages/numpy/core/../../../../libcblas.3.dylib' (no such file), '/Users/jeremy/miniforge3/envs/tf_m1/lib/libcblas.3.dylib' (no such file), '/Users/jeremy/miniforge3/envs/tf_m1/lib/libcblas.3.dylib' (no such file), '/Users/jeremy/miniforge3/envs/tf_m1/lib/python3.9/site-packages/numpy/core/../../../../libcblas.3.dylib' (no such file), '/Users/jeremy/miniforge3/envs/tf_m1/lib/libcblas.3.dylib' (no such file), '/Users/jeremy/miniforge3/envs/tf_m1/bin/../lib/libcblas.3.dylib' (no such file), '/Users/jeremy/miniforge3/envs/tf_m1/lib/libcblas.3.dylib' (no such file), '/Users/jeremy/miniforge3/envs/tf_m1/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:

Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "/Users/jeremy/miniforge3/envs/tf_m1/lib/python3.9/site-packages/tensorflow/__init__.py", line 41, in <module>
  from tensorflow.python.tools import module_util as _module_util
 File "/Users/jeremy/miniforge3/envs/tf_m1/lib/python3.9/site-packages/tensorflow/python/__init__.py", line 41, in <module>
  from tensorflow.python.eager import context
 File "/Users/jeremy/miniforge3/envs/tf_m1/lib/python3.9/site-packages/tensorflow/python/eager/context.py", line 30, in <module>
  import numpy as np
 File "/Users/jeremy/miniforge3/envs/tf_m1/lib/python3.9/site-packages/numpy/__init__.py", line 140, in <module>
  from . import core
 File "/Users/jeremy/miniforge3/envs/tf_m1/lib/python3.9/site-packages/numpy/core/__init__.py", line 48, 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.9 from "/Users/jeremy/miniforge3/envs/tf_m1/bin/python"
 * The NumPy version is: "1.19.5"

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/jeremy/miniforge3/envs/tf_m1/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so, 0x0002): Library not loaded: @rpath/libcblas.3.dylib
 Referenced from: /Users/jeremy/miniforge3/envs/tf_m1/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so
 Reason: tried: '/Users/jeremy/miniforge3/envs/tf_m1/lib/libcblas.3.dylib' (no such file), '/Users/jeremy/miniforge3/envs/tf_m1/lib/libcblas.3.dylib' (no such file), '/Users/jeremy/miniforge3/envs/tf_m1/lib/python3.9/site-packages/numpy/core/../../../../libcblas.3.dylib' (no such file), '/Users/jeremy/miniforge3/envs/tf_m1/lib/libcblas.3.dylib' (no such file), '/Users/jeremy/miniforge3/envs/tf_m1/lib/libcblas.3.dylib' (no such file), '/Users/jeremy/miniforge3/envs/tf_m1/lib/python3.9/site-packages/numpy/core/../../../../libcblas.3.dylib' (no such file), '/Users/jeremy/miniforge3/envs/tf_m1/lib/libcblas.3.dylib' (no such file), '/Users/jeremy/miniforge3/envs/tf_m1/bin/../lib/libcblas.3.dylib' (no such file), '/Users/jeremy/miniforge3/envs/tf_m1/lib/libcblas.3.dylib' (no such file), '/Users/jeremy/miniforge3/envs/tf_m1/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)

Hi, I also have a MacBook Pro 2020 (M1), and found your post after running into similar issues. I was using another article describing the steps involved, but it didn't work.

I tried the the steps outlined in your post--and the Apple Developers article you cite--and, strangely, they worked on my set. There might be differences in the conda versions we used? I used Miniforge as outlined in these (otherwise older) instructions -- this worked up to the point of the Apple files, which are out of date. (The Apple guidance you gave is current). https://towardsdatascience.com/installing-tensorflow-on-the-m1-mac-410bb36b776

I hope this helps! Let me know if you need anything further.

Hi Tony, Thanks for responding! Would you mind running ls -l /path/to/conda/environment/lib/libcblas.3.dylib ? That seems to be the file that's tripping me up. I'm not sure what it's supposed to be or why my install keeps linking it to a non-existent file.

After some more experimentation, this gets me to a working install. At least, I can import tensorflow and numpy without an error.

conda create -n tf_m1 python=3.8
conda activate tf_m1
conda install numpy==1.19.5
conda uninstall libcblas
conda install --force-reinstall libcblas
conda install numpy==1.19.5
conda install -c apple tensorflow-deps=2.6
python -m pip install tensorflow-macos==2.6.0

Now the file that was previously creating a problem, libcblas.3.dylib is still a link, but now points to libcblas.3.9.0.dylib, which exists. I'm still not sure why it was pointing to libopenblas_vortexp-r0.3.17.dylib before.

tensorflow / numpy on M1 / Monterey
 
 
Q