Symbol not found error while importing tensorflow in M1 Macbook Pro

Hello there, I have installed tensorflow in my M1 Macbook Pro using these commands in a conda environment:

  1. conda install -c apple tensorflow-deps
  2. python -m pip install tensorflow-macos
  3. python -m pip install tensorflow-metal
  4. python -m pip install tensorflow-datasets
  5. conda install jupyter pandas numpy matplotlib scikit-learn

I did it following this instruction - https://github.com/mrdbourke/m1-machine-learning-test

But when I import the packages I installed it gives me an error message.

Here:

import numpy as np
import pandas as pd
import sklearn
import tensorflow as tf
import matplotlib.pyplot as plt

# Check for TensorFlow GPU access
print(f"TensorFlow has access to the following devices:\n{tf.config.list_physical_devices()}")

# See TensorFlow version
print(f"TensorFlow version: {tf.__version__}")

Error:

---------------------------------------------------------------------------
NotFoundError                             Traceback (most recent call last)
Input In [1], in <cell line: 4>()
      2 import pandas as pd
      3 import sklearn
----> 4 import tensorflow as tf
      5 import matplotlib.pyplot as plt
      7 # Check for TensorFlow GPU access

File ~/miniforge3/lib/python3.9/site-packages/tensorflow/__init__.py:443, in <module>
    441 _plugin_dir = _os.path.join(_s, 'tensorflow-plugins')
    442 if _os.path.exists(_plugin_dir):
--> 443   _ll.load_library(_plugin_dir)
    444   # Load Pluggable Device Library
    445   _ll.load_pluggable_device_library(_plugin_dir)

File ~/miniforge3/lib/python3.9/site-packages/tensorflow/python/framework/load_library.py:151, in load_library(library_location)
    148     kernel_libraries = [library_location]
    150   for lib in kernel_libraries:
--> 151     py_tf.TF_LoadLibrary(lib)
    153 else:
    154   raise OSError(
    155       errno.ENOENT,
    156       'The file or folder to load kernel libraries from does not exist.',
    157       library_location)

NotFoundError: dlopen(/Users/arannya/miniforge3/lib/python3.9/site-packages/tensorflow-plugins/libmetal_plugin.dylib, 6): Symbol not found: __ZNKSt3__115basic_stringbufIcNS_11char_traitsIcEENS_9allocatorIcEEE3strEv
  Referenced from: /Users/arannya/miniforge3/lib/python3.9/site-packages/tensorflow-plugins/libmetal_plugin.dylib (which was built for Mac OS X 12.3)
  Expected in: /usr/lib/libc++.1.dylib

Please help me solve this issue. I have to make a robot for a competition. So I gotta run TensorFlow.

Answered by wangcheng in 719977022

Maybe your macOS version is not compatible? You need at least macOS 12.0+. https://developer.apple.com/metal/tensorflow-plugin/

I'm using 12.4 and no issue importing tensorflow.

Accepted Answer

Maybe your macOS version is not compatible? You need at least macOS 12.0+. https://developer.apple.com/metal/tensorflow-plugin/

I'm using 12.4 and no issue importing tensorflow.

Hi, you might need to match the version of your tensorflow-deps and tensorflow-macos.

I was having the same issue when I realized that conda install -c apple tensorflow-deps installed tensorflow-deps version 2.9.0, while python -m pip install tensorflow-macos installed tensorflow-macos version 2.11.0. Reinstalling both tensorflow-macos and tensorflow-machine to version 2.9.0 and 0.6.0 solved my issue.

run this command to reinstall both tensorflow-macos and tensorflow-machine and remove existing pacakges:

python -m pip install tensorflow-macos==2.9.0 tensorflow-machine==0.6.0 --force-reinstall

hope it helps

I'm sorry, it's not tensorflow-machine, it's tensorflow-metal, I don't know why I typed machine instead of metal there.

I'm using macOS 13.1 and had the same problem. I followed the instruction in https://developer.apple.com/metal/tensorflow-plugin/, and tensorflow-deps 2.10, tensorflow-macos 2.11, tensorflow-metal 0.7.0 were installed originally.
I re-installed tensorflow-deps 2.10, tensorflow-macos 2.10 and tensorflow-metal 0.6.0, then I could import tensorflow. (matched the version of tensorflow-deps and tensorflow-macos and downgraded tensorflow-metal as suggested above.)

Symbol not found error while importing tensorflow in M1 Macbook Pro
 
 
Q