我根据Tensorflow官方教程安装了环境,但是示例代码运行不正确

问题描述 投票:0回答:1

我根据Tensorflow的官方教程安装了环境,但是示例代码无法正确运行:

  1. 安装蟒蛇
  2. 通过conda create --name tensorflow python=3.7.4安装python
  3. 通过pip install --upgrade --ignore-installed tensorflow安装张量流
  4. 创建一个新项目并选择我安装的现有解释器
  5. 在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))

追踪(最近通话):

  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().
python tensorflow pycharm anaconda
1个回答
0
投票
东西是
© www.soinside.com 2019 - 2024. All rights reserved.