AttributeError: module ‘distutils‘ has no attribute ‘version‘解决跑pytorch代码报错

跑pytorch代码报错AttributeError: module ‘distutils’ has no attribute ‘version’

在这里插入图片描述

Traceback (most recent call last):
File “D:/pycharm_envir/gaozhiyuan/Segmentation/pytorch_segmentation/deeplabv3-plus-pytorch-main/train.py”, line 16, in
from utils.callbacks import LossHistory, EvalCallback
File “D:pycharm_envirgaozhiyuanSegmentationpytorch_segmentationdeeplabv3-plus-pytorch-mainutilscallbacks.py”, line 17, in
from torch.utils.tensorboard import SummaryWriter
File “C:softwareanaconda3envspytorch_gaolibsite-packagestorchutilstensorboard_init_.py”, line 4, in
LooseVersion = distutils.version.LooseVersion
AttributeError: module ‘distutils’ has no attribute ‘version’

网上大多数方法是说使用pip uninstall setuptools卸载最新的setuptools,然后安装较老版本的

但是这个方法,亲测不太好用

这里建议直接使用pycharm修改源代码

第一步,进入这个代码里边
在这里插入图片描述
第二步,分别注释这几行代码

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 LooseVersion
在这里插入图片描述
注释完就可以正常运行了