安装的tensor版本不同,导致测试的命令有所不同。无法执行sess.run()的原因是tensorflow1.0版本和2.0版本不同导致的。
安装的是tensorflow1.x版本使用以下命令测试运行tensorflow:
TF1.x hello world:
import tensorflow as tf
msg = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(msg))
安装的是tensorflow2.x版本使用以下命令测试运行tensorflow:
TF2.x hello world:
import tensorflow as tf
msg = tf.constant('Hello, TensorFlow!')
tf.print(msg)
若是在2.x版本运行1.x的测试脚本,就会出现no module “Session”
这时可改用2.x版本脚本,
若还要继续使用Session模板,
用 tf.compat.v1.Session()
代替 tf.Session()
并在这段代码最前面加入:
tf.compat.v1.disable_eager_execution()