10

I have installed tensorflow from Source on Ubuntu 16.10 environment. Everything went smooth but now on compiling a program, it shows the following error:

Traceback (most recent call last):
  File "ff.py", line 3, in <module>
    sess = tf.InteractiveSession()
AttributeError: module 'tensorflow' has no attribute 'InteractiveSession'

Didn't find any post related to this. Could someone please help?

talonmies
  • 70,661
  • 34
  • 192
  • 269
Saurav--
  • 1,530
  • 2
  • 15
  • 33

4 Answers4

23
sess=tf.compat.v1.InteractiveSession()

Use above line instead of sess = tf.InteractiveSession() line, if you are using tesorflow 2.0.0 version

Word Rearranger
  • 1,306
  • 1
  • 16
  • 25
11

The error causes from Tensorflow version. When you've install v2.x and try to use v1.x, you'll get this error. To avoid this,

import tensorflow as tf
import tensorflow.compat.v1 as tfc

Use tfc instead of tf when you get the same error on the other functions like:

sess = tfc.InteractiveSession()

my_tensor = tfc.random_uniform((4, 4), 0, 1)
print(my_tensor)
Oguzhan Bolukbas
  • 504
  • 6
  • 13
1

Today I got the same error after instaling tenserflow-serving-api. I installed tensorflow again and everything went back to normal.

Mehraban
  • 3,164
  • 4
  • 37
  • 60
0

Use the magic line:

%tensorflow_version 1.x
Bruno De Freitas Barros
  • 2,199
  • 2
  • 17
  • 16