如何修复:模块“tensorflow”没有属性“Session”

Atu*_*non 4 python machine-learning data-science tensorflow

import tensorflow as tf
a=tf.constant(2)
b=tf.constant(3)
c=a+b
sess=tf.Session(c)
sess.run()
Run Code Online (Sandbox Code Playgroud)

我收到错误消息模块“tensorflow”没有属性“Session”

J. *_*Doe 5

从官方文档尝试以下操作:

# 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))
Run Code Online (Sandbox Code Playgroud)