【问题标题】:How do I launch Tensorboard?如何启动 Tensorboard?
【发布时间】:2026-02-12 02:55:02
【问题描述】:

我正在关注https://www.tensorflow.org/guide/low_level_intro 上有关 Tensorflow 的介绍性指南,并设法使用

创建了一个“events.out”文件
writer = tf.summary.FileWriter('.')
writer.add_graph(tf.get_default_graph())
writer.flush() 

在我的 python 文件中并运行它。下一步是使用“shell 命令”tensorboard --logdir 在“终端”中启动 Tensorboard。这个怎么做?我应该使用什么终端?我试过windows powershell,但它似乎不起作用。它给出了错误

tensorboard : 术语“tensorboard”未被识别为 cmdlet、函数、脚本文件或可运行的程序。检查 名称的拼写,或者如果包含路径,请验证路径 是正确的,然后再试一次。在行:1 字符:1 +张量板--logdir + ~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (tensorboard:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

【问题讨论】:

  • 你安装了tensorflow吗? tensorflow.org/install
  • 是的,我已经安装了 tensorflow。
  • 您是否在 Jupyter Notebook 中运行 Python 代码?如果是这样,您在命令行上运行 tensorboard 时是否激活了相同的(虚拟)环境?
  • 在 Windows 中,也许您需要将 Tensorboard 目录添加到路径变量中,或者提供 tensorboard.exe 的完整位置,或者使用 Anaconda Prompt 或 Git CMD 等其他终端。 Anaconda Prompt 和 Git CMD 都可以在我的 Win7 桌面上运行。
  • @bartcode 不,我只是直接用 python.exe 运行它。 Jupyter 的优势是什么,我该如何使用它?

标签: python tensorflow tensorboard


【解决方案1】:

使用 PowerShell 没问题。听起来您的 PATH 未配置为像其他人所说的那样查找 Tensorboard 二进制文件。你能告诉我你从pip show tensorflow得到什么吗?它应该有如下内容:

(1) ➜  ~ pip show tensorflow
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Name: tensorflow
Version: 1.12.0
Summary: TensorFlow is an open source machine learning framework for everyone.
Home-page: https://www.tensorflow.org/
Author: Google Inc.
Author-email: opensource@google.com
License: Apache 2.0
Location: c:\users\stephanwlee\venv\tf\lib\site-packages
Requires: enum34, keras-preprocessing, wheel, astor, backports.weakref, mock, tensorboard, termcolor, protobuf, gast, absl-py, grpcio, six, keras-applications, numpy
Required-by:

在上面的输出中,位置是告诉您二进制文件大致放置在哪里的重要部分。如果您像 TensorFlow 安装指南一样使用 virtualenv(一切都应该无缝设置,我建议您使用它),二进制文件应该在 c:\users\stephanwlee\venv\tf\Scripts 中。请检查路径是否在$env:path

如果其中任何一个没有帮助,请在回复中添加来自 PowerShell 的 pip show tensorflow$env:path 的结果,谢谢!

【讨论】:

    【解决方案2】:
    pip show tensorflow
    Name: tensorflow
    Version: 2.7.0
    Summary: TensorFlow is an open source machine learning framework for everyone.
    Home-page: https://www.tensorflow.org/
    Author: Google Inc.
    Author-email: packages@tensorflow.org
    License: Apache 2.0
    Location: c:\users\luis\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages
    Requires: absl-py, astunparse, flatbuffers, gast, google-pasta, grpcio, h5py, keras, keras-preprocessing, libclang, numpy, opt-einsum, protobuf, six, tensorboard, tensorflow-estimator, tensorflow-io-gcs-filesystem, termcolor, typing-extensions, wheel, wrapt
    Required-by:
       LUIS@XEONE5-2620-v2  ~ 
    ❯
       LUIS@XEONE5-2620-v2  ~ 
    ❯ $env:path
    C:\Program Files\Microsoft MPI\Bin\;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\mingw64\bin;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\150\Tools\Binn\;C:\Program Files\Microsoft SQL Server\150\Tools\Binn\;C:\Program Files\Microsoft SQL Server\150\DTS\Binn\;C:\Program Files\Azure Data Studio\bin;C:\Strawberry\c\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin;C:\Program Files\MiKTeX\miktex\bin\x64\;C:\Program Files (x86)\Cracklock\Bin;C:\Users\LUIS\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Azure Data Studio\bin;;C:\Users\LUIS\AppData\Local\Programs\oh-my-posh\bin;C:\Users\LUIS\AppData\Local\Programs\oh-my-posh\themes;D:\Program Files\Microsoft VS Code\bin
    

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center