tensorflow报错raise RuntimeError('The Session graph is empty. Add operations to the '
RuntimeError: The Session graph is empty. Add operations to the graph before calling run().
这个是在安装tensorflow的时候为了测试安装是否成功,然后就用了网上的方法,但是在运行如下代码的时候却产生了错误
import tensorflow as tf
import os
# os.environ["TF_CPP_MIN_LOG_LEVEL"]='1' # 这是默认的显示等级,显示所有信息
os.environ["TF_CPP_MIN_LOG_LEVEL"]='2'
sess = tf.Session()
a = tf.constant(2)
b = tf.constant(2)
print(sess.run(a+b))
一开始是怀疑自己本地问题tensorflow没有下载全,后来百度了下没有解决,又想到是不是安装过程出错了,问题还真的就在这里,在我创建好tensorflow环境后,执行pip install tensorflow 这个默认下载的是2.0.0版本的,但是conda却不支持,所以我们在下载前要看看conda支持的tensorflow
版本,执行下边命令conda search --full -name tensorflow,如图
![](https://img-blog.csdnimg.cn/20191113100025344.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0pvaG5MZWVL,size_16,color_FFFFFF,t_70)
好了到这里我们根据自己的tensorflow的python版本选择就好了,然后执行
pip install tensorflow==1.x.x就好了