close

[Solved] AttributeError: module ‘tensorflow_core.compat.v1’ has no attribute ‘contrib’

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error AttributeError: module ‘tensorflow_core.compat.v1’ has no attribute ‘contrib’ in Python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How AttributeError: module ‘tensorflow_core.compat.v1’ has no attribute ‘contrib’ Error Occurs?

Today I get the following error AttributeError: module ‘tensorflow_core.compat.v1’ has no attribute ‘contrib’ in Python.

How To Solve AttributeError: module ‘tensorflow_core.compat.v1’ has no attribute ‘contrib’ Error ?

  1. How To Solve AttributeError: module 'tensorflow_core.compat.v1' has no attribute 'contrib' Error ?

    To Solve AttributeError: module 'tensorflow_core.compat.v1' has no attribute 'contrib' Error I think you need to add the following line in your python file which you are going to execute it. import tensorflow.compat.v1 as tf tf.disable_v2_behavior()

Solution 1

tf.contrib was removed from TensorFlow once with TensorFlow 2.0 alpha version.

Most likely, you are already using TensorFlow 2.0.

You can find more details here: https://github.com/tensorflow/tensorflow/releases/tag/v2.0.0-alpha0

For using specific versions of tensorflow, use

pip install tensorflow==1.14

or

pip install tensorflow-gpu==1.14

Solution 2

I think you need to add the following line in your python file which you are going to execute it.


import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also Read

Leave a Comment