跑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_envir\gaozhiyuan\Segmentation\pytorch_segmentation\deeplabv3-plus-pytorch-main\utils\callbacks.py”, line 17, in
from torch.utils.tensorboard import SummaryWriter
File “C:\software\anaconda3\envs\pytorch_gao\lib\site-packages\torch\utils\tensorboard_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

注释完就可以正常运行了