Can't import tensorflow_decision_forests, getting NotFoundError

I’m trying to import tensorflow_decision_forests in python like this:

import tensorflow_decision_forests as tfdf

And I keep getting the error I’ve included below. My tensorflow version is 2.11.0 and my tensorflow_decision_forests version is 1.2.0 so those should be compatible. I also am using Python version 3.10.11 and my macOS is version 10.14.5, so all of that should be fine. I tried uninstalling and installing tensorflow and tensorflow_decision_forests as well as downgrading to previous compatible versions of tensorflow and tensorflow_decision_forests and nothing has worked. Does anyone know whats going on? Here is the error:


NotFoundError Traceback (most recent call last)
Cell In[1], line 12
10 from scipy.stats import boxcox
11 import tensorflow as tf
—> 12 import tensorflow_decision_forests as tfdf
13 import pandas as pd
15 train_data = pd.read_csv(“train_housing.csv”)

File /anaconda3/envs/py10/lib/python3.10/site-packages/tensorflow_decision_forests/init.py:64
60 from tensorflow_decision_forests.tensorflow import check_version
62 check_version.check_version(version, compatible_tf_versions)
—> 64 from tensorflow_decision_forests import keras
65 from tensorflow_decision_forests.component import py_tree
66 from tensorflow_decision_forests.component.builder import builder

File /anaconda3/envs/py10/lib/python3.10/site-packages/tensorflow_decision_forests/keras/init.py:53
15 “”“Decision Forest in a Keras Model.
16
17 Usage example:
(…)
48 ```
49 “””
51 from typing import Callable, List
—> 53 from tensorflow_decision_forests.keras import core
54 from tensorflow_decision_forests.keras import wrappers
56 # Utility classes

File /anaconda3/envs/py10/lib/python3.10/site-packages/tensorflow_decision_forests/keras/core.py:61
59 from tensorflow_decision_forests.component.inspector import inspector as inspector_lib
60 from tensorflow_decision_forests.component.tuner import tuner as tuner_lib
—> 61 from tensorflow_decision_forests.keras import core_inference
62 from tensorflow_decision_forests.tensorflow import core as tf_core
63 from tensorflow_decision_forests.tensorflow import tf1_compatibility

File /anaconda3/envs/py10/lib/python3.10/site-packages/tensorflow_decision_forests/keras/core_inference.py:36
34 from tensorflow_decision_forests.tensorflow import core_inference as tf_core
35 from tensorflow_decision_forests.tensorflow import tf_logging
—> 36 from tensorflow_decision_forests.tensorflow.ops.inference import api as tf_op
37 from yggdrasil_decision_forests.learner import abstract_learner_pb2
38 from yggdrasil_decision_forests.learner.multitasker import multitasker_pb2

File /anaconda3/envs/py10/lib/python3.10/site-packages/tensorflow_decision_forests/tensorflow/ops/inference/api.py:179
177 from tensorflow_decision_forests.component.inspector import inspector as inspector_lib
178 from tensorflow_decision_forests.tensorflow import tf1_compatibility
→ 179 from tensorflow_decision_forests.tensorflow.ops.inference import op
180 from yggdrasil_decision_forests.dataset import data_spec_pb2
181 from yggdrasil_decision_forests.model import abstract_model_pb2

File /anaconda3/envs/py10/lib/python3.10/site-packages/tensorflow_decision_forests/tensorflow/ops/inference/op.py:15
1 # Copyright 2021 Google LLC.
2 #
3 # Licensed under the Apache License, Version 2.0 (the “License”);
(…)
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
—> 15 from tensorflow_decision_forests.tensorflow.ops.inference.op_dynamic import *

File /anaconda3/envs/py10/lib/python3.10/site-packages/tensorflow_decision_forests/tensorflow/ops/inference/op_dynamic.py:24
22 except Exception as e:
23 check_version.info_fail_to_load_custom_op(e, “inference.so”)
—> 24 raise e
26 # Importing all the symbols.
27 module = sys.modules[name]

File /anaconda3/envs/py10/lib/python3.10/site-packages/tensorflow_decision_forests/tensorflow/ops/inference/op_dynamic.py:21
18 import sys
20 try:
—> 21 ops = tf.load_op_library(resource_loader.get_path_to_datafile(“inference.so”))
22 except Exception as e:
23 check_version.info_fail_to_load_custom_op(e, “inference.so”)

File /anaconda3/envs/py10/lib/python3.10/site-packages/tensorflow/python/framework/load_library.py:54, in load_op_library(library_filename)
31 @tf_export(‘load_op_library’)
32 def load_op_library(library_filename):
33 “”“Loads a TensorFlow plugin, containing custom ops and kernels.
34
35 Pass “library_filename” to a platform-specific mechanism for dynamically
(…)
52 RuntimeError: when unable to load the library or get the python wrappers.
53 “””
—> 54 lib_handle = py_tf.TF_LoadLibrary(library_filename)
55 try:
56 wrappers = _pywrap_python_op_gen.GetPythonWrappers(
57 py_tf.TF_GetOpList(lib_handle))

NotFoundError: dlopen(/anaconda3/envs/py10/lib/python3.10/site-packages/tensorflow_decision_forests/tensorflow/ops/inference/inference.so, 6): no suitable image found. Did find:
/anaconda3/envs/py10/lib/python3.10/site-packages/tensorflow_decision_forests/tensorflow/ops/inference/inference.so: cannot load ‘inference.so’ (load command 0x80000034 is unknown)
/anaconda3/envs/py10/lib/python3.10/site-packages/tensorflow_decision_forests/tensorflow/ops/inference/inference.so: cannot load ‘inference.so’ (load command 0x80000034 is unknown)

Hi @Nicolas_Lukan, I have installed python, tensorflow, tensorflow_decision_forests with the above mentioned versions i didn’t get any error.
9QYmQnRe3mgcp9i

Could you please try to create a new virtual environment and check if you are able to import tensorflow_decision_forests. Thank You.

1 Like

Hey @Kiran_Sai_Ramineni thanks for the input, I tried creating a new environment but am getting the same error, would anything else cause this?

Hi,

Richard from the TF-DF team here. Apologies for the issues you’re seeing and thank you for the detailed bug report.

The issue you’re facing is hard to reproduce for me - I won’t be able to get my hands on a device with this exact OS, since MacOS 10.14 has not gotten security updates for nearly two years. But we can try narrowing down the problem: Does the issue occur when running outside an Anaconda environment (using just stock Python)?

Hey @rstz, thanks for getting back. Sorry it’s been a couple days

So i just tried it on my command line through a virtual environment and making sure that my python wasn’t imported from anaconda and I am getting the same error.

Did you ever figure out what your issue was?
I have the same issue with inference.so claiming not to be found.
Windows 11, Python 3.11.6, Tensorflow 2.15.0, Tensorflow_decision_forests 1.8.1
Using IntelliJ with pointing to the Python directory (non-VE).
When I try to import the tensorflow_decision_forest in python I get the below error:

WARNING:root:Failure to load the inference.so custom c++ tensorflow ops. This error is likely caused the version of TensorFlow and TensorFlow Decision Forests are not compatible. Full error:F:\DevTools\Python311\Lib\site-packages\tensorflow_decision_forests\tensorflow\ops\inference\inference.so not found

The file is there. I checked multiple times. The python path is env. variables.
I uninstalled and re-installed probably 20 times. Everything looks clean and right.

1 Like

Had the same issue with keras installed and everything.
My keras was 3.0.5 and I just did a
pip install tf_keras
This reinstalled it to 2.15 version.
Now the import works properly.
Maybe something to check there.