module 'tensorflow' has no attribute 'Session'
时间: 2023-09-24 09:06:23 浏览: 31
This error typically occurs when you try to use the `Session` class from TensorFlow 1.x in TensorFlow 2.x. In TensorFlow 2.x, the eager execution mode is enabled by default, and you don't need to use the `Session` class to run TensorFlow operations.
To resolve this error, you can either:
1. Switch to using TensorFlow 1.x by installing it and importing it with `import tensorflow as tf` instead of `import tensorflow`.
2. Update your code to use TensorFlow 2.x API and avoid using the `Session` class. Instead, use the `tf.function` decorator to define your graph and the `tf.Tensor` class to represent your data. For example, to create a tensor in TensorFlow 2.x, you can use the following code:
```
import tensorflow as tf
x = tf.constant([1, 2, 3])
print(x)
```
This will create a tensor with the values `[1, 2, 3]` and print it.