I m facing the ModuleNotFoundError: No module named 'tensorflow.compat'

ModuleNotFoundError Traceback (most recent call last)
C:\Windows\Temp\ipykernel_22880\2911687784.py in
----> 1 import tensorflow.compat.v2 as tf

~\AppData\Roaming\Python\Python39\site-packages\tensorflow_init_.py in
35 import typing as _typing
—> 37 from tensorflow.python.tools import module_util as _module_util
38 from tensorflow.python.util.lazy_loader import LazyLoader as _LazyLoader

~\AppData\Roaming\Python\Python39\site-packages\tensorflow\python_init_.py in
105 from tensorflow.python.platform import test
→ 107 from tensorflow.python.compat import v2_compat
109 from tensorflow.python.util.all_util import make_all

~\AppData\Roaming\Python\Python39\site-packages\tensorflow\python\compat\v2_compat.py in
17 from tensorflow.python import tf2
—> 18 import tensorflow.compat.v1 as tf
19 from tensorflow.python.data.experimental.ops import counter
20 from tensorflow.python.data.experimental.ops import interleave_ops

ModuleNotFoundError: No module named ‘tensorflow.compat’

Hi @Shravani_tajane, I was able to import tf.compat.v1 in colab with TF 2.15.0 version without any error. please refer to this gist. Also tf.compat was deprecated.I recommend you to migrate your code to tf2.x. Thank You.

in colab it is run but not in jupyter

Hi @Shravani_tajane, I have tried to import tf.compat.v1 in jupyter notebook and did not face any error.

Thank You.