报错信息为:AttributeError: module ‘tensorflow’ has no attribute ‘Session
解决办法:
将import tensorflow as tf 写为import tensorflow.compat.v1 as tf
import tensorflow.compat.v1 as tf
后面又报错:RuntimeError: The Session graph is empty. Add operations to the graph before calling run().
此时添加:
tf.compat.v1.disable_eager_execution()
然后问题解决!
激活TensorFlow:
conda activate tf
退出TensorFlow:
conda deactivate
参考资料:
添加链接描述