How to fix : module 'tensorflow' has no attribute 'Session'

Written by- Aionlinecourse1048 times views

It looks like you are trying to use the tensorflow module, but are encountering an error saying that it has no attribute Session. Here are a few things you can try to resolve this issue:

1.Make sure that you have installed the latest version of TensorFlow. You can check the version of TensorFlow that you have installed by running pip freeze | grep tensorflow. If you do not have TensorFlow installed, you can install it by running pip install tensorflow.
2.Make sure that you are using the correct import statement. The Session class is part of the tensorflow.compat.v1 module, so you will need to use from tensorflow.compat.v1 import Session in your code.
3.If you are using an older version of TensorFlow (prior to version 2.0), you may need to use tf.Session instead of tensorflow.Session.
4.If you have recently upgraded TensorFlow, it is possible that the code you are using was written for an older version and is no longer compatible with the latest version. In this case, you may need to update your code to use the latest TensorFlow API.