close

[Solved] AttributeError: module ‘tensorflow’ has no attribute ‘Session’

Hello Guys, How are you all? Hope You all Are Fine. Today I am just using tensorflow session using tf.Session() but I am facing following error AttributeError: module ‘tensorflow’ has no attribute ‘Session’ 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’ has no attribute ‘Session’ Error Occurs ?

I am just using tensorflow session using tf.Session() but I am facing following error.

AttributeError: module 'tensorflow' has no attribute 'Session'

How To Solve AttributeError: module ‘tensorflow’ has no attribute ‘Session’ Error ?

  1. How To Solve AttributeError: module 'tensorflow' has no attribute 'Session' Error ?

    To Solve AttributeError: module 'tensorflow' has no attribute 'Session' Error If You are using tensorFlow 2.0 then Just use session with compat v1 just like below tf.compat.v1.Session() instead of tf.Session(). Second Solution is “Session()” has been removed with TF 2.0. you can use tf.compat.v1.Session()

  2. AttributeError: module 'tensorflow' has no attribute 'Session'

    To Solve AttributeError: module 'tensorflow' has no attribute 'Session' Error If You are using tensorFlow 2.0 then Just use session with compat v1 just like below tf.compat.v1.Session() instead of tf.Session(). Second Solution is “Session()” has been removed with TF 2.0. you can use tf.compat.v1.Session()

Solution 1: use session with compat v1

If You are using tensorFlow 2.0 then Just use session with compat v1 just like below.

tf.compat.v1.Session()

instead of

tf.Session()

Solution 2: For TensorFlow 1.X

If You are using TensorFlow 1.X then just use this sample.

import tensorflow as tf
msg = tf.constant('Hello world!!')
sess = tf.Session()

Soltion 3: “Session()” has been removed with TF 2.0

“Session()” has been removed with TF 2.0.

import tensorflow as tf

tf.compat.v1.disable_eager_execution()
arg = tf.constant('Hello, World!!')
sess = tf.compat.v1.Session()

print(sess.run(arg))

Summary

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?

Also, Read

Please Rate Our Solution to Motivate Us For Give Our Best

Leave a Comment