7

I found a chatbot program in github and wanted to run this program for my better understanding. But every time I try to run this program, it says

No module named 'tensorflow.contrib'

What should I do to fix this error?

3
  • 3
    Possible duplicate of ImportError: No module named 'tensorflow.contrib.data' Commented Mar 23, 2019 at 7:23
  • I tried to fix with the answers provided in this question but it didn't work at all. plz, help. Commented Mar 23, 2019 at 7:29
  • what is the tf.__version__? Commented Mar 23, 2019 at 11:01

4 Answers 4

3

Probably the code you found was written in TensorFlow 1.x, but you have TensorFlow 2.x installed. Instead of downgrading TensorFlow, the compatibility module can be used:

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

Source:https://www.tensorflow.org/guide/migrate

Sign up to request clarification or add additional context in comments.

1 Comment

I am using python==3.11.7 and tensorflow==2.15.0. this unfortunately doesn't work for me. thank you all the same!
2

tf.contrib.data has been deprecated and been removed
Try downgrade version of tensorflow:

pip3 install tensorflow==1.14

use venv to install multiple tensorflow version on single machine

Comments

1

Explained by other expert: An interesting find, I hope this helps others that are developing under Anaconda or similar integrated environments where your program isn't ran directly from the command line, e.g. like "python myprogram.py".

The problem could be caused by the fact that the program itself is named tensorflow.py. It is being run in an environment where it isn't started as the "main" module, but is loaded by another Python program (anaconda, in this case).

When a python program is loaded this way, the interpreter reads it as a module and puts it in its list of modules (under the same name as the file), so now you have sys.modules["tensorflow"] that points to the loaded user program (and NOT to the installed tensorflow module). When the 'import tensorflow as tf' line is encountered, Python sees that "tensorflow" is already imported and simply does tf=sys.modules["tensorflow"], which is a reference to your own tensorflow.py (already a problem, but you haven't got to tf.enable_eager_execution() yet - it would fail if you did, because your tensorflow.py doesn't have such a function).

Now, the interesting part:

import tensorflow.contrib.eager as tfe

Python already has 'tensorflow' imported (your module!), so it expects to find any sub-modules in the same directory as the loaded tensorflow.py. In particular, it expects that directory to be a Python package (have init.py in it), but it obviously does not, hence the "... is not a package" error message.

1 Comment

also check your latest python version.
0

Probably you are trying to run it over Windows, try to run it in your terminal:

pip install cloudbiolinux==0.3a

pip install helper

pip install contrib

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.