Cannot import tensorflow in Python3 in MacOS 12.6.1 on M1 Mac

I'm trying to use tensorflow per this tutorial for arm64 Apple Silicon: https://developer.apple.com/metal/tensorflow-plugin/

However, when I attempt to import tensorflow, I get this error:


RuntimeError Traceback (most recent call last) RuntimeError: module compiled against API version 0x10 but this version of numpy is 0xf Output exceeds the size limit. Open the full output data in a text editor

ImportError Traceback (most recent call last) ImportError: numpy.core.multiarray failed to import

The above exception was the direct cause of the following exception:

SystemError Traceback (most recent call last) SystemError: <built-in method contains of dict object at 0x107c68040> returned a result with an error set

The above exception was the direct cause of the following exception:

ImportError Traceback (most recent call last) Cell In [2], line 1 ----> 1 import tensorflow as tf

File ~/opt/miniconda3/envs/speaker_recognition/lib/python3.8/site-packages/tensorflow/init.py:37 34 import sys as _sys 35 import typing as _typing ---> 37 from tensorflow.python.tools import module_util as _module_util 38 from tensorflow.python.util.lazy_loader import LazyLoader as _LazyLoader 40 # Make sure code inside the TensorFlow codebase can use tf2.enabled() at import.

File ~/opt/miniconda3/envs/speaker_recognition/lib/python3.8/site-packages/tensorflow/python/init.py:37 29 # We aim to keep this file minimal and ideally remove completely. 30 # If you are adding a new file with @tf_export decorators, ... ---> 19 from tensorflow.python.client._pywrap_tf_session import * 20 from tensorflow.python.client._pywrap_tf_session import _TF_SetTarget 21 from tensorflow.python.client._pywrap_tf_session import _TF_SetConfig

ImportError: initialization failed

What else can I try to get tensorflow operational and using my M1's GPU?

Hi @tambo,

Please try updating numpy: pip3 install numpy --upgrade --ignore-installed

Aha! I'd been so close, but combining the upgrade and ignore-installed arguments was the missing piece! THANK YOU, Frameworks Engineer! Tensorflow now imports into my Python environment on my M1 Mac.

Cannot import tensorflow in Python3 in MacOS 12.6.1 on M1 Mac
 
 
Q