Cannot import name "type_spec_registry" from "tensorflow.python.framework"

I am new to tensorflow and am trying to follow a tutorial on enviroments when this error appeared. I looked in the file and there is no “type_spec_registry” there. How would i go about downloading “type_spec_registry”?

@Havard_Hauge,

Welcome to the Tensorflow Forum!

I followed TF-Agents Environments tutorial and it is working as expected on Colab using TF 2.11.0 and tf-agents 0.15.0.

To debug the above issues, please share the standalone code and steps that you have followed to install tf-agents and operating system details?

Thank you!

Thank you for a quick reply!

I did pip install “gym>=0.21.0” on the terminal in pycharm
and so pip install tf-agents[reverb]
I tried reinstalling both to see if this would work but it did not work

Operating system details:
Processor: AMD Ryzen 5 4500U with Radeon Graphics 2.38 GHz
Installed RAM: 8.00 GB (7.40 GB usable)
System type:64-bit operating system, x64-based processor

this is the code that remains as i removed code from the tutorial to narrow down the issue:

from future import absolute_import
from future import division
from future import print_function

import abc
import tensorflow as tf
import numpy as np

from tf_agents.environments import py_environment
from tf_agents.environments import tf_environment
from tf_agents.environments import tf_py_environment
from tf_agents.environments import utils
from tf_agents.specs import array_spec
from tf_agents.environments import wrappers
from tf_agents.environments import suite_gym
from tf_agents.trajectories import time_step as ts

and this is the whole error message

File “C:\Users\havar\PycharmProjects\pythonProject\Tekforsk\Tensorflow enviroment.py”, line 9, in
from tf_agents.environments import py_environment
File “C:\Users\havar\PycharmProjects\pythonProject\venv\lib\site-packages\tf_agents\environments_init_.py”, line 18, in
from tf_agents.environments import batched_py_environment
File “C:\Users\havar\PycharmProjects\pythonProject\venv\lib\site-packages\tf_agents\environments\batched_py_environment.py”, line 32, in
from tf_agents.environments import py_environment
File “C:\Users\havar\PycharmProjects\pythonProject\venv\lib\site-packages\tf_agents\environments\py_environment.py”, line 29, in
from tf_agents.trajectories import time_step as ts
File “C:\Users\havar\PycharmProjects\pythonProject\venv\lib\site-packages\tf_agents\trajectories_init_.py”, line 19, in
from tf_agents.trajectories import time_step
File “C:\Users\havar\PycharmProjects\pythonProject\venv\lib\site-packages\tf_agents\trajectories\time_step.py”, line 28, in
from tf_agents.specs import array_spec
File “C:\Users\havar\PycharmProjects\pythonProject\venv\lib\site-packages\tf_agents\specs_init_.py”, line 20, in
from tf_agents.specs.distribution_spec import DistributionSpec
File “C:\Users\havar\PycharmProjects\pythonProject\venv\lib\site-packages\tf_agents\specs\distribution_spec.py”, line 22, in
import tensorflow_probability as tfp
File “C:\Users\havar\PycharmProjects\pythonProject\venv\lib\site-packages\tensorflow_probability_init_.py”, line 20, in
from tensorflow_probability import substrates
File “C:\Users\havar\PycharmProjects\pythonProject\venv\lib\site-packages\tensorflow_probability\substrates_init_.py”, line 17, in
from tensorflow_probability.python.internal import all_util
File “C:\Users\havar\PycharmProjects\pythonProject\venv\lib\site-packages\tensorflow_probability\python_init_.py”, line 138, in
dir(globals()[pkg_name]) # Forces loading the package from its lazy loader.
File “C:\Users\havar\PycharmProjects\pythonProject\venv\lib\site-packages\tensorflow_probability\python\internal\lazy_loader.py”, line 57, in dir
module = self.load()
File “C:\Users\havar\PycharmProjects\pythonProject\venv\lib\site-packages\tensorflow_probability\python\internal\lazy_loader.py”, line 40, in load
module = importlib.import_module(self.name)
File "C:\Users\havar\AppData\Local\Programs\Python\Python39\lib\importlib_init
.py", line 127, in import_module
return bootstrap.gcd_import(name[level:], package, level)
File "C:\Users\havar\PycharmProjects\pythonProject\venv\lib\site-packages\tensorflow_probability\python\experimental_init
.py", line 31, in
from tensorflow_probability.python.experimental import bijectors
File "C:\Users\havar\PycharmProjects\pythonProject\venv\lib\site-packages\tensorflow_probability\python\experimental\bijectors_init
.py", line 17, in
from tensorflow_probability.python.bijectors.ldj_ratio import forward_log_det_jacobian_ratio
File "C:\Users\havar\PycharmProjects\pythonProject\venv\lib\site-packages\tensorflow_probability\python\bijectors_init
.py", line 19, in
from tensorflow_probability.python.bijectors.absolute_value import AbsoluteValue
File “C:\Users\havar\PycharmProjects\pythonProject\venv\lib\site-packages\tensorflow_probability\python\bijectors\absolute_value.py”, line 19, in
from tensorflow_probability.python.bijectors import bijector
File “C:\Users\havar\PycharmProjects\pythonProject\venv\lib\site-packages\tensorflow_probability\python\bijectors\bijector.py”, line 25, in
from tensorflow_probability.python.internal import auto_composite_tensor
File “C:\Users\havar\PycharmProjects\pythonProject\venv\lib\site-packages\tensorflow_probability\python\internal\auto_composite_tensor.py”, line 27, in
from tensorflow.python.framework import type_spec_registry
ImportError: cannot import name ‘type_spec_registry’ from ‘tensorflow.python.framework’

I got the same error;

It turns out that there is no type_spec_registry, but type_spec under tensorflow.python.framework

I am using tensorflow 2.11.0 on centOS, with python 3.9.16

error log:

from tensorflow.keras import datasets
Traceback (most recent call last):
File “”, line 1, in
File “/home/yuyang/miniconda3/envs/esm/lib/python3.9/site-packages/keras/api/_v2/keras/init.py”, line 12, in
from keras import version
File “/home/yuyang/miniconda3/envs/esm/lib/python3.9/site-packages/keras/init.py”, line 21, in
from keras import models
File “/home/yuyang/miniconda3/envs/esm/lib/python3.9/site-packages/keras/models/init.py”, line 18, in
from keras.engine.functional import Functional
File “/home/yuyang/miniconda3/envs/esm/lib/python3.9/site-packages/keras/engine/functional.py”, line 26, in
from keras import backend
File “/home/yuyang/miniconda3/envs/esm/lib/python3.9/site-packages/keras/backend.py”, line 35, in
from keras.engine import keras_tensor
File “/home/yuyang/miniconda3/envs/esm/lib/python3.9/site-packages/keras/engine/keras_tensor.py”, line 19, in
from keras.utils import object_identity
File “/home/yuyang/miniconda3/envs/esm/lib/python3.9/site-packages/keras/utils/init.py”, line 53, in
from keras.utils.feature_space import FeatureSpace
File “/home/yuyang/miniconda3/envs/esm/lib/python3.9/site-packages/keras/utils/feature_space.py”, line 20, in
from keras.engine import base_layer
File “/home/yuyang/miniconda3/envs/esm/lib/python3.9/site-packages/keras/engine/base_layer.py”, line 39, in
from keras.engine import node as node_module
File “/home/yuyang/miniconda3/envs/esm/lib/python3.9/site-packages/keras/engine/node.py”, line 28, in
from keras.saving.legacy.saved_model import json_utils
File “/home/yuyang/miniconda3/envs/esm/lib/python3.9/site-packages/keras/saving/legacy/saved_model/json_utils.py”, line 36, in
from tensorflow.python.framework import type_spec_registry

It turns out that there is no type_spec_registry, but type_spec under tensorflow.python.framework

>>> import tensorflow.python.framework as fr
>>> dir(fr)
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '_dtypes', '_op_def_library_pybind', '_op_def_registry', '_proto_comparators', '_pywrap_python_api_dispatcher', '_pywrap_python_op_gen', '_test_metrics_util', 'auto_control_deps', 'auto_control_deps_utils', 'c_api_util', 'combinations', 'common_shapes', 'composite_tensor', 'composite_tensor_gradient', 'config', 'constant_op', 'convert_to_constants', 'cpp_shape_inference_pb2', 'device', 'device_spec', 'dtypes', 'error_interpolation', 'errors', 'errors_impl', 'extension_type', 'extension_type_field', 'fast_tensor_util', 'func_graph', 'function', 'function_def_to_graph', 'gpu_util', 'graph_io', 'graph_to_function_def', 'graph_util', 'graph_util_impl', 'immutable_dict', 'importer', 'indexed_slices', 'kernels', 'load_library', 'meta_graph', 'op_callbacks', 'op_def_library', 'op_def_library_pybind', 'op_def_registry', 'ops', 'random_seed', 'registry', 'smart_cond', 'sparse_tensor', 'tensor_conversion_registry', 'tensor_shape', 'tensor_spec', 'tensor_util', 'test_combinations', 'test_util', 'tfrt_utils', 'traceable_stack', 'type_spec', 'type_utils', 'versions']

I