trfl: ImportError: cannot import name gen_distribution_ops

When I try to import trfl, similarly to this public trfl colab notebook online, I get

(Note I tried this in both python 2 and 3 notebooks, met with the same results)

<ipython-input-3-dd69192d7d7c> in <module>()
----> 1 import trfl

/usr/local/lib/python2.7/dist-packages/trfl/__init__.py in <module>()
     29 from trfl.discrete_policy_gradient_ops import discrete_policy_gradient_loss
     30 from trfl.discrete_policy_gradient_ops import sequence_advantage_actor_critic_loss
---> 31 from trfl.dist_value_ops import categorical_dist_double_qlearning
     32 from trfl.dist_value_ops import categorical_dist_qlearning
     33 from trfl.dist_value_ops import categorical_dist_td_learning

/usr/local/lib/python2.7/dist-packages/trfl/dist_value_ops.py in <module>()
     31 import tensorflow as tf
     32 from trfl import base_ops
---> 33 from trfl import distribution_ops
     34 
     35 Extra = collections.namedtuple("dist_value_extra", ["target"])

/usr/local/lib/python2.7/dist-packages/trfl/distribution_ops.py in <module>()
     28 import tensorflow as tf
     29 import tensorflow_probability as tfp
---> 30 from trfl import gen_distribution_ops
     31 
     32 

ImportError: cannot import name gen_distribution_ops

(Also, if I install trfl via pip instead of cloning from git, error messages look similar with this added on the end)


/usr/local/lib/python2.7/dist-packages/trfl/gen_distribution_ops.py in <module>()
      1 import tensorflow as tf
----> 2 _op_lib = tf.load_op_library(tf.resource_loader.get_path_to_datafile("_gen_distribution_ops.so"))
      3 project_distribution = _op_lib.project_distribution
      4 del _op_lib, tf

/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/load_library.pyc in load_op_library(library_filename)
     59     RuntimeError: when unable to load the library or get the python wrappers.
     60   """
---> 61   lib_handle = py_tf.TF_LoadLibrary(library_filename)
     62 
     63   op_list_str = py_tf.TF_GetOpList(lib_handle)

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 19 (8 by maintainers)

Most upvoted comments

@mtthss The gen_distribution_ops.so seems to be missing when installing in a fresh environment with TF 13.1 and TF-Probability 0.6 on macOS.

› pip list | grep tensorflow
tensorflow             1.13.1
tensorflow-estimator   1.13.0
tensorflow-probability 0.6.0
Python 3.6.8 |Anaconda, Inc.| (default, Dec 29 2018, 19:04:46)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import trfl

WARNING: The TensorFlow contrib module will not be included in TensorFlow 2.0.
For more information, please see:
  * https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md
  * https://github.com/tensorflow/addons
If you depend on functionality not listed there, please file an issue.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/Abdel/Developer/anaconda/envs/tf2/lib/python3.6/site-packages/trfl/__init__.py", line 31, in <module>
    from trfl.dist_value_ops import categorical_dist_double_qlearning
  File "/Users/Abdel/Developer/anaconda/envs/tf2/lib/python3.6/site-packages/trfl/dist_value_ops.py", line 33, in <module>
    from trfl import distribution_ops
  File "/Users/Abdel/Developer/anaconda/envs/tf2/lib/python3.6/site-packages/trfl/distribution_ops.py", line 30, in <module>
    from trfl import gen_distribution_ops
  File "/Users/Abdel/Developer/anaconda/envs/tf2/lib/python3.6/site-packages/trfl/gen_distribution_ops.py", line 2, in <module>
    _op_lib = tf.load_op_library(tf.resource_loader.get_path_to_datafile("_gen_distribution_ops.so"))
  File "/Users/Abdel/Developer/anaconda/envs/tf2/lib/python3.6/site-packages/tensorflow/python/framework/load_library.py", line 61, in load_op_library
    lib_handle = py_tf.TF_LoadLibrary(library_filename)
tensorflow.python.framework.errors_impl.NotFoundError: dlopen(/Users/Abdel/Developer/anaconda/envs/tf2/lib/python3.6/site-packages/trfl/_gen_distribution_ops.so, 6): image not found
Name: trfl
Version: 1.0
Summary: trfl is a library of building blocks for reinforcement learning algorithms.
Home-page: http://www.github.com/deepmind/trfl/
Author: DeepMind
Author-email: trfl-steering@google.com
License: Apache 2.0
Location: /Users/Abdel/Developer/anaconda/envs/tf2/lib/python3.6/site-packages
Requires: numpy, six, dm-sonnet, absl-py, wrapt
Required-by:
Files:
  trfl-1.0.dist-info/INSTALLER
  trfl-1.0.dist-info/LICENSE
  trfl-1.0.dist-info/METADATA
  trfl-1.0.dist-info/RECORD
  trfl-1.0.dist-info/WHEEL
  trfl-1.0.dist-info/top_level.txt
  trfl/__init__.py
  trfl/__pycache__/__init__.cpython-36.pyc
  trfl/__pycache__/action_value_ops.cpython-36.pyc
  trfl/__pycache__/base_ops.cpython-36.pyc
  trfl/__pycache__/clipping_ops.cpython-36.pyc
  trfl/__pycache__/discrete_policy_gradient_ops.cpython-36.pyc
  trfl/__pycache__/dist_value_ops.cpython-36.pyc
  trfl/__pycache__/distribution_ops.cpython-36.pyc
  trfl/__pycache__/dpg_ops.cpython-36.pyc
  trfl/__pycache__/gen_distribution_ops.cpython-36.pyc
  trfl/__pycache__/indexing_ops.cpython-36.pyc
  trfl/__pycache__/periodic_ops.cpython-36.pyc
  trfl/__pycache__/pixel_control_ops.cpython-36.pyc
  trfl/__pycache__/policy_gradient_ops.cpython-36.pyc
  trfl/__pycache__/retrace_ops.cpython-36.pyc
  trfl/__pycache__/sequence_ops.cpython-36.pyc
  trfl/__pycache__/target_update_ops.cpython-36.pyc
  trfl/__pycache__/value_ops.cpython-36.pyc
  trfl/__pycache__/vtrace_ops.cpython-36.pyc
  trfl/action_value_ops.py
  trfl/base_ops.py
  trfl/clipping_ops.py
  trfl/discrete_policy_gradient_ops.py
  trfl/dist_value_ops.py
  trfl/distribution_ops.py
  trfl/dpg_ops.py
  trfl/gen_distribution_ops.py
  trfl/indexing_ops.py
  trfl/periodic_ops.py
  trfl/pixel_control_ops.py
  trfl/policy_gradient_ops.py
  trfl/retrace_ops.py
  trfl/sequence_ops.py
  trfl/target_update_ops.py
  trfl/value_ops.py
  trfl/vtrace_ops.py

@akanksha95, @abdel,

we now have pre-built binaries for both MacOS and Ubuntu you can install them with pip install trfl

  • Ubuntu: make sure you have TensorFlow 1.12.0 and TensorFlow Probability 0.5
  • MacOS: make sure you have TensorFlow 1.13.1 and TensorFlow Probability 0.6