Error while importing TensorFlow

Hello Everyone!

I recently tried installing TensorFlow following this guide: https://developer.apple.com/metal/tensorflow-plugin/ on my M1 Pro MacBook running 12.4 Monterey. However, I'm faced with the following error message when importing:

File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/python/framework/dtypes.py:29, in <module>
     26 from tensorflow.python.lib.core import _pywrap_bfloat16
     27 from tensorflow.python.util.tf_export import tf_export
---> 29 _np_bfloat16 = _pywrap_bfloat16.TF_bfloat16_type()
     32 @tf_export("dtypes.DType", "DType")
     33 class DType(_dtypes.DType):
     34   """Represents the type of the elements in a `Tensor`.
     35 
     36   `DType`'s are used to specify the output data type for operations which
   (...)
     46   See `tf.dtypes` for a complete list of `DType`'s defined.
     47   """

TypeError: Unable to convert function return value to a Python type! The signature was
	() -> handle

I've checked that my tensoflow-dep has a version of 2.9.0, tensorflow-macos 2.9.2, and tensor flow-metal 0.5.0, with numpy having its latest version of 1.22.4, all in my env.

Anyone knows what's up?

Post not yet marked as solved Up vote post of bckhm Down vote post of bckhm
1.6k views

Replies

Hi @bckhm

I think I've seen this before when a non-macos tensorflow has been installed into the same environment as the tensorflow-macos. Can you check what the running python -m pip list inside your environment you are trying to import tensorflow prints out? It should show that you have tensorflow-macos and tensorflow-metal installed but not tensorflow.

I have no other tensorflow installed instead tensorflow-macos and TensorFlow-metal, but still having the same error. Any suggestions?

So what is the solution? I'm following these instructions to install tensorflow on my mac M1: https://developer.apple.com/metal/tensorflow-plugin/ but I'm getting the same error.