Running tensorflow-macos 2.11.0 give runtime error on Apple Mac M1

Question:

I’m using PyCharme on Apple MacBook air M1 to learn basics of TensorFlow. I have used Anaconda to create the development environment with below details:

  • python 3.9.15
  • tensorflow-macos 2.11.0
  • tensorflow-metal 0.7.0
  • numpy 1.21.5

I have imported tensorflow in my code as below:

import os
import tensorflow as tf
import pandas as pd
from sklearn.preprocessing import MinMaxScaler

When run this codein my "training_loop final.py" file , Im getting runtime error as below:

/Users/kapo/opt/anaconda3/envs/env_tf/bin/python /Users/kapo/PycharmProjects/tensorflow-course/03/training_loop final.py 
RuntimeError: module compiled against API version 0x10 but this version of numpy is 0xf
RuntimeError: module compiled against API version 0x10 but this version of numpy is 0xf
ImportError: numpy.core._multiarray_umath failed to import
ImportError: numpy.core.umath failed to import
Traceback (most recent call last):
  File "/Users/kapo/PycharmProjects/tensorflow-course/03/training_loop final.py", line 2, in <module>
    import tensorflow as tf
  File "/Users/kapo/opt/anaconda3/envs/env_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/kapo/opt/anaconda3/envs/env_tf/lib/python3.9/site-packages/tensorflow/python/__init__.py", line 42, in <module>
    from tensorflow.python import data
  File "/Users/kapo/opt/anaconda3/envs/env_tf/lib/python3.9/site-packages/tensorflow/python/data/__init__.py", line 21, in <module>
    from tensorflow.python.data import experimental
  File "/Users/kapo/opt/anaconda3/envs/env_tf/lib/python3.9/site-packages/tensorflow/python/data/experimental/__init__.py", line 96, in <module>
    from tensorflow.python.data.experimental import service
  File "/Users/kapo/opt/anaconda3/envs/env_tf/lib/python3.9/site-packages/tensorflow/python/data/experimental/service/__init__.py", line 419, in <module>
    from tensorflow.python.data.experimental.ops.data_service_ops import distribute
  File "/Users/kapo/opt/anaconda3/envs/env_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/kapo/opt/anaconda3/envs/env_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/kapo/opt/anaconda3/envs/env_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/kapo/opt/anaconda3/envs/env_tf/lib/python3.9/site-packages/tensorflow/python/data/util/nest.py", line 34, in <module>
    from tensorflow.python.framework import sparse_tensor as _sparse_tensor
  File "/Users/kapo/opt/anaconda3/envs/env_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/kapo/opt/anaconda3/envs/env_tf/lib/python3.9/site-packages/tensorflow/python/framework/constant_op.py", line 25, in <module>
    from tensorflow.python.eager import execute
  File "/Users/kapo/opt/anaconda3/envs/env_tf/lib/python3.9/site-packages/tensorflow/python/eager/execute.py", line 21, in <module>
    from tensorflow.python.framework import dtypes
  File "/Users/kapo/opt/anaconda3/envs/env_tf/lib/python3.9/site-packages/tensorflow/python/framework/dtypes.py", line 34, in <module>
    _np_bfloat16 = _pywrap_bfloat16.TF_bfloat16_type()
TypeError: Unable to convert function return value to a Python type! The signature was
    () -> handle

Process finished with exit code 1

Anyone know how I can fix this? and it mean by "module compiled against API version 0x10 but this version of numpy is 0xf"

Asked By: user3588569

||

Answers:

tensorflow-macos 2.11.0 will not run with your current environment.

You need to upgrade python to 3.10 to run tensorflow-macos 2.10.0.

You also have a missing dependency in numpy, so it’s best you upgrade that to 1.23.4 at least.

Answered By: lilbronto
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.