Error when importing TensorFlow on macOS 13.0

system info: macOS 13.0 14 inch M1 Pro (2021 generation) I tried to import TensorFlow as our official guide instructs: https://developer.apple.com/metal/tensorflow-plugin/

but something happens, I cannot import TensorFlow after trying to upgrade numpy or TensorFlow-macos or something else, like our forum discusses.

I will be appraised if anyone could help me with that, please let me know

numpy                     1.21.5           py39h42add53_3    defaults
numpy-base                1.21.5           py39hadd41eb_3    defaults
tensorflow-estimator      2.9.0                    pypi_0    pypi
tensorflow-macos          2.9.2                    pypi_0    pypi
tensorflow-metal          0.5.1                    pypi_0    pypi
(tf) gary@192 ~ % python

Python 3.9.15 (main, Nov  4 2022, 11:12:28) 

[Clang 12.0.0 ] :: Anaconda, Inc. on darwin

Type "help", "copyright", "credits" or "license" for more information.

>>> import tensorflow

RuntimeError: module compiled against API version 0xf but this version of numpy is 0xe

RuntimeError: module compiled against API version 0xf but this version of numpy is 0xe

ImportError: numpy.core._multiarray_umath failed to import

ImportError: numpy.core.umath failed to import

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "/Users/gary/Documents/anaconda3/envs/tf/lib/python3.9/site-packages/tensorflow/__init__.py", line 37, in <module>

    from tensorflow.python.tools import module_util as _module_util

  File "/Users/gary/Documents/anaconda3/envs/tf/lib/python3.9/site-packages/tensorflow/python/__init__.py", line 42, in <module>

    from tensorflow.python import data

  File "/Users/gary/Documents/anaconda3/envs/tf/lib/python3.9/site-packages/tensorflow/python/data/__init__.py", line 21, in <module>

    from tensorflow.python.data import experimental

  File "/Users/gary/Documents/anaconda3/envs/tf/lib/python3.9/site-packages/tensorflow/python/data/experimental/__init__.py", line 95, in <module>

    from tensorflow.python.data.experimental import service

  File "/Users/gary/Documents/anaconda3/envs/tf/lib/python3.9/site-packages/tensorflow/python/data/experimental/service/__init__.py", line 387, in <module>

    from tensorflow.python.data.experimental.ops.data_service_ops import distribute

  File "/Users/gary/Documents/anaconda3/envs/tf/lib/python3.9/site-packages/tensorflow/python/data/experimental/ops/data_service_ops.py", line 22, in <module>

    from tensorflow.python.data.experimental.ops import compression_ops

  File "/Users/gary/Documents/anaconda3/envs/tf/lib/python3.9/site-packages/tensorflow/python/data/experimental/ops/compression_ops.py", line 16, in <module>

    from tensorflow.python.data.util import structure

  File "/Users/gary/Documents/anaconda3/envs/tf/lib/python3.9/site-packages/tensorflow/python/data/util/structure.py", line 22, in <module>

    from tensorflow.python.data.util import nest

  File "/Users/gary/Documents/anaconda3/envs/tf/lib/python3.9/site-packages/tensorflow/python/data/util/nest.py", line 36, in <module>

    from tensorflow.python.framework import sparse_tensor as _sparse_tensor

  File "/Users/gary/Documents/anaconda3/envs/tf/lib/python3.9/site-packages/tensorflow/python/framework/sparse_tensor.py", line 24, in <module>

    from tensorflow.python.framework import constant_op

  File "/Users/gary/Documents/anaconda3/envs/tf/lib/python3.9/site-packages/tensorflow/python/framework/constant_op.py", line 25, in <module>

    from tensorflow.python.eager import execute

  File "/Users/gary/Documents/anaconda3/envs/tf/lib/python3.9/site-packages/tensorflow/python/eager/execute.py", line 23, in <module>

    from tensorflow.python.framework import dtypes

  File "/Users/gary/Documents/anaconda3/envs/tf/lib/python3.9/site-packages/tensorflow/python/framework/dtypes.py", line 29, in <module>

    _np_bfloat16 = _pywrap_bfloat16.TF_bfloat16_type()

TypeError: Unable to convert function return value to a Python type! The signature was

	() -> handle

>>> 

Replies

Problem solved.

the import error is caused by numpy version mismatch, which is quite annoying.

you can update your numpy to the latest by

pip install numpy --upgrade --ignore-installed