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

这是一次傻逼的经历,突然报如下错误,我以为是环境坏掉了,重装环境搞了半天,猜猜最后是什么原因?

Traceback (most recent call last):
  File "/home/leerw/.local/lib/python3.6/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.summary'; 'tensorboard' is not a package

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "../util/torch_nn.py", line 19, in <module>
    from pytorch_lightning import LightningModule
  File "/home/leerw/.local/lib/python3.6/site-packages/pytorch_lightning/__init__.py", line 31, in <module>
    from .trainer import Trainer
  File "/home/leerw/.local/lib/python3.6/site-packages/pytorch_lightning/trainer/__init__.py", line 28, in <module>
    from .trainer import Trainer
  File "/home/leerw/.local/lib/python3.6/site-packages/pytorch_lightning/trainer/trainer.py", line 15, in <module>
    from pytorch_lightning.loggers import LightningLoggerBase
  File "/home/leerw/.local/lib/python3.6/site-packages/pytorch_lightning/loggers/__init__.py", line 78, in <module>
    from .tensorboard import TensorBoardLogger
  File "/home/leerw/.local/lib/python3.6/site-packages/pytorch_lightning/loggers/tensorboard.py", line 8, in <module>
    from torch.utils.tensorboard import SummaryWriter
  File "/home/leerw/.local/lib/python3.6/site-packages/torch/utils/tensorboard/__init__.py", line 4, in <module>
    raise ImportError('TensorBoard logging requires TensorBoard with Python summary writer installed. '
ImportError: TensorBoard logging requires TensorBoard with Python summary writer installed. This should be available in 1.14 or above.

最后查到原因是我在该目录下创建了一个tensorboard.py文件,但是什么都没写。看看pytorch背地里干了什么勾当?

try:
    from tensorboard.summary.writer.record_writer import RecordWriter  # noqa F401
except ImportError:
    raise ImportError('TensorBoard logging requires TensorBoard with Python summary writer installed. '
                      'This should be available in 1.14 or above.')
from .writer import FileWriter, SummaryWriter  # noqa F401

怪不得我在别的文件夹执行

from torch.utils.tensorboard import SummaryWriter

没有问题

该问题过于傻逼,写下来纪念一下。

如果你也遇到了这个问题,但是不像我一样傻逼的话,下面这个链接可能会帮到你:
https://github.com/pytorch/pytorch/issues/20140

你可能感兴趣的:(snippets)