我正在使用Pycharm与python 3.9,torch 1.8.1+cu111和tensorboard 2.6.0.当我尝试导入SummaryWriter时:
from torch.utils.tensorboard import SummaryWriter
出现以下错误:
* Traceback (most recent call last):
File "/data/heisery/Yaronhome/PycharmProjects/CSSC_pytorch/tensorboard.py", line 18, in <module>
from torch.utils.tensorboard import SummaryWriter
File "/usr/local/lib/python3.8/dist-packages/torch/utils/tensorboard/__init__.py", line 1, in <module>
import tensorboard
File "/data/heisery/Yaronhome/PycharmProjects/CSSC_pytorch/tensorboard.py", line 18, in <module>
from torch.utils.tensorboard import SummaryWriter*
**ImportError: cannot import name 'SummaryWriter' from partially initialized module 'torch.utils.tensorboard' (most likely due to a circular import) (/usr/local/lib/python3.8/dist-packages/torch/utils/tensorboard/__init__.py)**
这是我的导入列表:
import torch
import torch.nn as nn
from torch.utils.data import DataLoader
import torchvision
import torchvision.transforms as transforms
import matplotlib.pyplot as plt
import sys
from torch.utils.tensorboard import SummaryWriter
writer = SummaryWriter('runs/mnist')
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
1条答案
按热度按时间sqxo8psd1#
兄弟,我刚刚解决了一个类似的问题。只要确保你的文件名不是“tensorboard”。