question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ImportError: cannot import name gen_distribution_ops

See original GitHub issue

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)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:19 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
abdelcommented, Mar 17, 2019

@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
1reaction
mtthsscommented, Mar 14, 2019

@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
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix ImportError: Cannot Import Name in Python - Rollbar
The Python ImportError: cannot import name error occurs when an imported class is not accessible or is in a circular dependency.
Read more >
What can I do about "ImportError: Cannot import name X" or ...
You have circular dependent imports. physics.py is imported from entity before class Ent is defined and physics tries to import entity that is...
Read more >
cannot import name 'remote_pb2' from 'securexgboost.rpc ...
I am getting the following error importing securexgboost: secureml@fml-30294-westus2-sxgb-poc-sgxvm:~$ python3 Python 3.7.5 (default, ...
Read more >
How to Fix : “ImportError: Cannot import name X” in Python?
You can solve the “ ImportError : Cannot import name X” Error by resolving the circular dependencies. You can do that either by...
Read more >
cannot import name 'file_hash' from 'pooch.utils' - YouTube
How to resolve ImportError : cannot import name 'file_hash' from 'pooch.utils'
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found