Error regarding numpy version after installing tensor flow-macos

I tried installing tensorflow by following the guideline at https://developer.apple.com/metal/tensorflow-plugin/ inside of a conda environment. The installation works fine, but when trying to run the verification script at the end of the guide, it fails at import tensorflow as tf and I get the following error:

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/username/Desktop/test1.py", line 5, in <module>

    import tensorflow as tf

...

The version of numpy installed by running conda install -c apple tensorflow-deps is 1.22.3, but the error seems to suggest that this is not compatible with tensorflow.

Any advice on how to fix that would be much appreciated!

Post not yet marked as solved Up vote post of Mac4Ever Down vote post of Mac4Ever
2.8k views
Add a Comment

Replies

I am also experiencing the same problem following exactly the same instructions. The snipped bit of traceback in addition to the OP is as follows:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/matt/miniconda/lib/python3.10/site-packages/tensorflow/__init__.py", line 37, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "/Users/matt/miniconda/lib/python3.10/site-packages/tensorflow/python/__init__.py", line 42, in <module>
    from tensorflow.python import data
  File "/Users/matt/miniconda/lib/python3.10/site-packages/tensorflow/python/data/__init__.py", line 21, in <module>
    from tensorflow.python.data import experimental
  File "/Users/matt/miniconda/lib/python3.10/site-packages/tensorflow/python/data/experimental/__init__.py", line 96, in <module>
    from tensorflow.python.data.experimental import service
  File "/Users/matt/miniconda/lib/python3.10/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/matt/miniconda/lib/python3.10/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/matt/miniconda/lib/python3.10/site-packages/tensorflow/python/data/experimental/ops/compression_ops.py", line 16, in <module>
    from tensorflow.python.data.util import structure
  File "/Users/matt/miniconda/lib/python3.10/site-packages/tensorflow/python/data/util/structure.py", line 22, in <module>
    from tensorflow.python.data.util import nest
  File "/Users/matt/miniconda/lib/python3.10/site-packages/tensorflow/python/data/util/nest.py", line 34, in <module>
    from tensorflow.python.framework import sparse_tensor as _sparse_tensor
  File "/Users/matt/miniconda/lib/python3.10/site-packages/tensorflow/python/framework/sparse_tensor.py", line 24, in <module>
    from tensorflow.python.framework import constant_op
  File "/Users/matt/miniconda/lib/python3.10/site-packages/tensorflow/python/framework/constant_op.py", line 25, in <module>
    from tensorflow.python.eager import execute
  File "/Users/matt/miniconda/lib/python3.10/site-packages/tensorflow/python/eager/execute.py", line 21, in <module>
    from tensorflow.python.framework import dtypes
  File "/Users/matt/miniconda/lib/python3.10/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```

So looks as simple as the version of numpy is quite old for the version of Tensor Flow. Whilst in the miniconda environment one just needs to run the following to get the right dependency:

python -m pip install numpy --upgrade

Post not yet marked as solved Up vote reply of Ulti Down vote reply of Ulti
  • Thanks a lot! That also fixed it for me. I had tried something like this before posting about the issue, but apparently I did something wrong.

  • Thank you for the fix! Please consider filing a bug report with the Feedback Assistant.

  • Sorted part of the problem.

Add a Comment

Thanks. It did solve the problem though funnily it also showed that:

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. tensorflow-macos 2.12.0 requires numpy<1.24,>=1.22, but you have numpy 1.24.3 which is incompatible.

The program did successfully run though with this warning:

W tensorflow/tsl/platform/profile_utils/cpu_utils.cc:128] Failed to get CPU frequency: 0 Hz

Hi, I ran into the exact same issue.

The solution for me what not to run python -m pip install numpy --upgrade as it updated to numpy 1.24.3 which is also incompatible. I got

tensorflow-macos 2.12.0 requires numpy&lt;1.24,>=1.22, but you have numpy 1.24.3 which is incompatible.

However, runningpython3 -m pip install tensorflow-macos "numpy==1.23" solved my error completely.

Hope it helps!