ImportError: TensorBoard logging requires TensorBoard with Python summary writer installed.

简介: 突然报如下错误,我以为是环境坏掉了,重装环境搞了半天,猜猜最后是什么原因?

Tensorboard原本是Google TensorFlow的可视化工具,可以用于记录训练数据、评估数据、网络结构、图像等,并且可以在web上展示,对于观察神经网络的过程非常有帮助。


项目场景:


突然报如下错误,我以为是环境坏掉了,重装环境搞了半天,猜猜最后是什么原因?


ImportError: TensorBoard logging requires TensorBoard with Python summary writer installed.


问题描述


---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
C:\ProgramData\Anaconda3\envs\fastai_v1\lib\site-packages\torch\utils\tensorboard\__init__.py in 
      1 try:
----> 2     from tensorboard.summary.writer.record_writer import RecordWriter  # noqa F401
      3 except ImportError:
ModuleNotFoundError: No module named 'tensorboard.summary'; 'tensorboard' is not a package
During handling of the above exception, another exception occurred:
ImportError                               Traceback (most recent call last)
c:\Users\matt\Documents\code\playground\tensorboard.py in 
----> 1 from torch.utils.tensorboard import SummaryWriter
      2 
      3 # default `log_dir` is "runs" - we'll be more specific here
      4 writer = SummaryWriter('runs/fashion_mnist_experiment_1')
C:\ProgramData\Anaconda3\envs\fastai_v1\lib\site-packages\torch\utils\tensorboard\__init__.py in 
      2     from tensorboard.summary.writer.record_writer import RecordWriter  # noqa F401
      3 except ImportError:
----> 4     raise ImportError('TensorBoard logging requires TensorBoard with Python summary writer installed. '
      5                       'This should be available in 1.14 or above.')
      6 from .writer import FileWriter, SummaryWriter  # noqa F401
ImportError: TensorBoard logging requires TensorBoard with Python summary writer installed. This should be available in 1.14 or above.


原因分析:


tensorboard的版本太低了


使用下面的版本安装新版本的tensorboard


解决方案:


如果还报有没有No module named ‘tensorboard’ 的错,则说明是由于没有安装tensorboard引起的,类似一下这种报错


Traceback (most recent call last):
  File "/home/../anaconda3/envs/pytorch/lib/python3.7/site-packages/torch/utils/tensorboard/__init__.py", line 2, in <module>
    from tensorboard.summary.writer.record_writer import RecordWriter  # noqa F401
ModuleNotFoundError: No module named 'tensorboard'


所以解决办法是安装tensorboard即可


如果确认安装了tensorboard 依然报错,应该和版本有关


安装新版本的tensorboard


conda install -c conda-forge tensorboard


可能存在的问题:


报错:TypeError: __init__() got an unexpected keyword argument 'serialized_options'


# 很可能是protobuf的版本不对导致的
# 可以先卸载掉protobuf,再重新安装
pip install -U protobuf


目录
相关文章
|
3月前
|
计算机视觉 Python
ERROR: Could not build wheels for opencv-python which use PEP 517 and cannot be installed directly
ERROR: Could not build wheels for opencv-python which use PEP 517 and cannot be installed directly
70 2
|
Ubuntu PyTorch 算法框架/工具
Python程序运行,“libgcc_s.so.1 must be installed for pthread_cancel to work”解决办法
Python程序运行,“libgcc_s.so.1 must be installed for pthread_cancel to work”解决办法
214 0
|
Python
RuntimeError: Python is not installed as a framework
RuntimeError: Python is not installed as a framework
115 0
|
7天前
|
算法 程序员 开发工具
百万级Python讲师又一力作!Python编程轻松进阶,豆瓣评分8.1
在学习Python的旅程中你是否正在“绝望的沙漠”里徘徊? 学完基础教程的你,是否还在为选择什么学习资料犹豫不决,不知从何入手,提高自己?
百万级Python讲师又一力作!Python编程轻松进阶,豆瓣评分8.1
|
5天前
|
算法 程序员 开发工具
百万级Python讲师又一力作!Python编程轻松进阶,豆瓣评分8.1
在学习Python的旅程中你是否正在“绝望的沙漠”里徘徊? 学完基础教程的你,是否还在为选择什么学习资料犹豫不决,不知从何入手,提高自己?
|
3天前
|
数据采集 存储 人工智能
掌握Python编程:从基础到进阶的实用指南
【8月更文挑战第17天】 本文旨在通过浅显易懂的语言和实际案例,为初学者和有一定基础的开发者提供一条清晰的Python学习路径。我们将从Python的基本语法入手,逐步深入到面向对象编程、数据科学应用及网络爬虫开发等高级主题。每个部分都配备了代码示例和实操建议,确保读者能够将理论知识转化为实际能力。无论你是编程新手,还是希望提升Python技能的开发者,这篇文章都将为你打开一扇通往高效编程世界的大门。
7 2
|
8天前
|
Python
python Process 多进程编程
python Process 多进程编程
19 1
|
12天前
|
存储 数据挖掘 程序员
揭秘Python:掌握这些基本语法和数据类型,你将拥有编程世界的钥匙!
【8月更文挑战第8天】Python是一种高级、解释型语言,以简洁的语法和强大的功能广受好评。本文从基本语法入手,强调Python独特的缩进规则,展示清晰的代码结构。接着介绍了Python的主要数据类型,包括数值、字符串、列表、元组、集合和字典,并提供了示例代码。通过这些基础知识的学习,你将为深入探索Python及其在文本处理、数据分析等领域的应用打下坚实的基础。
26 3
|
14天前
|
Python
揭秘!Python系统编程里那些让代码自由穿梭的神奇代码行
【8月更文挑战第6天】在Python编程中,一些简洁有力的代码构造让程序更加灵动高效。列表推导式能一行生成列表,如`squares = [x**2 for x in range(10)]`。`with`语句确保资源自动释放,例`with open(&#39;example.txt&#39;, &#39;r&#39;) as file:`。`lambda`函数便于快速定义小函数,`map(lambda x: x + 1, numbers)`即可完成列表映射。
28 4
|
14天前
|
API C语言 开发者
Python如何成为跨平台编程的超级巨星:系统调用深度探索
【8月更文挑战第6天】Python凭借简洁的语法和强大的库支持,在编程领域中脱颖而出。其跨平台特性是基于CPython等解释器的设计理念,使得Python程序能在不同操作系统上运行而无需修改代码。Python标准库提供的抽象层隐藏了系统间的差异,加之ctypes等扩展机制,使开发者能高效地编写兼容性强且性能优异的应用。例如,在Windows上利用ctypes调用GetSystemTime系统API获取当前时间,展现了Python深入系统底层的强大能力和灵活性。随着技术演进,Python将继续巩固其作为首选编程语言的地位。
19 3