【发布时间】:2020-03-07 02:53:30
【问题描述】:
我按照Tensorflow官方教程安装了环境,但是示例代码运行不正常:
- 安装 anaconda
- 通过
conda create --name tensorflow python=3.7.4安装python - 通过
pip install --upgrade --ignore-installed tensorflow安装tensorflow - 创建一个新项目并选择我安装的现有解释器
- 在pycharm中运行代码
有没有我遗漏的步骤?
import tensorflow as tf
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
hello = tf.constant("hello world")
sess = tf.compat.v1.Session()
print(sess.run(hello))
Traceback(最近一次调用最后一次):
File "E:/dp/dp_01/test.py", line 6, in <module>
print(sess.run(hello))
File "D:\Users\46173\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow_core\python\client\session.py", line 956, in run
run_metadata_ptr)
File "D:\Users\46173\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow_core\python\client\session.py", line 1105, in _run
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().
【问题讨论】:
-
我认为这不是官方的 TF 教程。从官网查看这个beginner教程
标签: python tensorflow pycharm anaconda