1

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"

  • Could you please also share information about numpy version you are using? Please check if this helps: https://developer.apple.com/forums/thread/687644. – medium-dimensional Dec 19 '22 at 12:31
  • I'm using numpy 1.21.5 –  Dec 19 '22 at 12:35
  • Please also check [What is the proper way to install TensorFlow on Apple M1 in 2022](https://stackoverflow.com/questions/72964800/what-is-the-proper-way-to-install-tensorflow-on-apple-m1-in-2022) and [Apple's tensorflow-metal installation instructions](https://developer.apple.com/metal/tensorflow-plugin/). – medium-dimensional Dec 19 '22 at 12:39
  • @KapoNYC, please let us know the pandas version, the error could be due to a higher version of pandas. Kindly try downgrading it and let us know if the issue still persists. Thank you! –  Dec 26 '22 at 05:51
  • This is my panda package details: Name: pandas Version: 1.5.2 –  Dec 26 '22 at 08:22
  • Please try downgrading pandas version to 1.3.5 and let us know if the issue still persists. Thank you! –  Dec 27 '22 at 05:12
  • I did and downgraded the pandas version to 1.3.5 but when I run my import line `from keras.models import Sequential` I get this error `from tensorflow.contrib.tensorboard.plugins import projector ModuleNotFoundError: No module named 'tensorflow.contrib` –  Dec 27 '22 at 10:01
  • @KapoNYC, it is better to use `tensorflow.keras`. A few years ago Keras was integrated into the TensorFlow, please try importing Sequential like this `from tensorflow.keras.models import Sequential`. –  Dec 29 '22 at 08:46
  • I tried what @Tfer3 suggested but it doesn't work. I fixed the issue when I followed the instruction from this post from Apple Inc. [link] (https://developer.apple.com/metal/tensorflow-plugin/) –  Jan 02 '23 at 06:30

1 Answers1

0

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.

Kyle
  • 3
  • 1
  • 3
lilbronto
  • 16
  • 1
  • Tensorflow currently [does not support python 3.11](https://www.tensorflow.org/install/pip#software_requirements) at all so python 3.10 should be good for it. – Forgotten-Storm Mar 01 '23 at 19:02