4
import tensorflow as tf
a=tf.constant(2)
b=tf.constant(3)
c=a+b
sess=tf.Session(c)
sess.run()

I got the error message module 'tensorflow' has no attribute 'Session'

Atul Menon
  • 51
  • 1
  • 1
  • 2
  • which Tensorflow version are you using? – Shubham Shaswat Mar 21 '20 at 11:14
  • 1
    Does this answer your question? [Tensorflow 2.0 - AttributeError: module 'tensorflow' has no attribute 'Session'](https://stackoverflow.com/questions/55142951/tensorflow-2-0-attributeerror-module-tensorflow-has-no-attribute-session) – Abhilash Chandran Mar 21 '20 at 12:08

2 Answers2

5

From the official doc try the following:

# Build a graph.
a = tf.constant(5.0)
b = tf.constant(6.0)
c = a * b

# Launch the graph in a session.
sess = tf.compat.v1.Session()

# Evaluate the tensor `c`.
print(sess.run(c))
J. Doe
  • 522
  • 6
  • 22
1

Try this way:

with tf.compat.v1.Session() as sess:

  a = tf.constant(5.0)
  b = tf.constant(6.0)
  c = tf.multiply(a, b)

  result = sess.run(c)
  print(result)
Shubham Shaswat
  • 1,250
  • 9
  • 14