赞
踩
根据这里所说,tensorboardX好像寄了,但是Pytorch官方给出了SummaryWriter作为替代品。
环境是Torch1.10.2+cu113,tensorboard2.8.0。
试图使用如下命令
from torch.utils.tensorboard import SummaryWriter
导入tensorboard,报错:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\Anaconda\envs\torchenv1100\lib\site-packages\torch\utils\tensorboard\__init__.py", line 4, in <module>
LooseVersion = distutils.version.LooseVersion
AttributeError: module 'distutils' has no attribute 'version'
根据这里的描述,原因是setuptools包版本过高,需要降低版本。
这里给出另外一个解决方案。打开Anaconda\envs\torchenv1100\lib\site-packages\torch\utils\tensorboard_init_.py文件
import tensorboard
from setuptools import distutils
LooseVersion = distutils.version.LooseVersion
if not hasattr(tensorboard, '__version__') or LooseVersion(tensorboard.__version__) < LooseVersion('1.15'):
raise ImportError('TensorBoard logging requires TensorBoard version 1.15 or above')
del distutils
del LooseVersion
del tensorboard
from .writer import FileWriter, SummaryWriter # noqa: F401
from tensorboard.summary.writer.record_writer import RecordWriter # noqa: F401
其中,第4-7行代码的本意是确保tensorboard版本要高于1.15(含)。但是由于setuptools在60.0之后版本中不存在“distutils.version.LooseVersion”,因此这里报错了。
手动检查tensorboard版本是否高于1.15(含),如确实满足要求,则将源代码中的如下部分注释掉。
import tensorboard
from setuptools import distutils
# LooseVersion = distutils.version.LooseVersion
# if not hasattr(tensorboard, '__version__') or LooseVersion(tensorboard.__version__) < LooseVersion('1.15'):
# raise ImportError('TensorBoard logging requires TensorBoard version 1.15 or above')
del distutils
#del LooseVersion
del tensorboard
from .writer import FileWriter, SummaryWriter # noqa: F401
from tensorboard.summary.writer.record_writer import RecordWriter # noqa: F401
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。