SkV
SkV

Reputation: 70

How to fix: "ModuleNotFoundError: No module named 'tensorflow.contrib'"

I'm trying to build an image classifier, and want to import tflearn.

# Importing the required libraries
import tflearn
from tflearn.layers.conv import conv_2d, max_pool_2d
from tflearn.layers.core import input_data, dropout, fully_connected
from tflearn.layers.estimator import regression
import tensorflow as tf

However, I'm unable to do so, due to the following error message.

File "imgclassification.py", line 97, in <module>
    import tflearn
  File "/usr/local/lib/python3.7/site-packages/tflearn/__init__.py", line 4, in <module>
    from . import config
  File "/usr/local/lib/python3.7/site-packages/tflearn/config.py", line 5, in <module>
    from .variables import variable
  File "/usr/local/lib/python3.7/site-packages/tflearn/variables.py", line 7, in <module>
    from tensorflow.contrib.framework.python.ops import add_arg_scope as contrib_add_arg_scope
ModuleNotFoundError: No module named 'tensorflow.contrib'

Apparently, tensorflow.contrib was deprecated in the latest release of TensorFlow.

The number of error messages increased when I uninstalled TensorFlow 2.0 and installed TensorFlow 1.14. Most of them are warnings.

How do I fix this?

Upvotes: 1

Views: 16913

Answers (4)

bmabir17
bmabir17

Reputation: 141

I have also faced same error. Solved it by using tensorflow v1.15.3

pip install tensorflow-gpu==1.15.3

Upvotes: 0

Anuraag Velamati
Anuraag Velamati

Reputation: 1

Please follow the below steps, it may help resolve the issue.

  1. Upgrade your python version to 3.6 or above.

  2. Downgrade/Upgrade your TensorFlow to version 1.14.0.

Hopefully, this should resolve the issue.

Upvotes: 0

Lakshmi - Intel
Lakshmi - Intel

Reputation: 601

When you install tensorflow, by default the latest version of tensorflow will install that is tensorflow 2.0 (now) and the code that you are running (imgclassification.py) suited to execute with tensorflow 1.* as it searches for tensorflow.contrib that is absent in 2.0. So downgrade tensorflow using the below command :

pip install tensorflow==1.14

Upvotes: 1

Arthur
Arthur

Reputation: 1

Maybe you can try the TensorFlow version of 1.12.0 I import them successfully in jupyter notebook. jupyter result

Upvotes: 0

Related Questions