运行SimpleNet执行run.sh时遇TypeError: 'NoneType'对象不可调用错误
运行SimpleNet时出现
TypeError: 'NoneType' object is not callable错误解决 错误输出
Matplotlib created a temporary cache directory at /tmp/matplotlib-ovjj_rt5 because the default path (/home/username/.config/matplotlib) is not a writable directory; it is highly recommended to set the MPLCONFIGDIR environment variable to a writable directory, in particular to speed up the import of Matplotlib and to better support multiprocessing. Traceback (most recent call last): File "main.py", line 43, in <module> @main.result_callback() TypeError: 'NoneType' object is not callable
复现步骤
- 在Windows 11系统上安装WSL 20.04
- 在WSL环境中安装Python 2.7和3.8.10
- 从源码编译并安装带Python支持的OpenCV 4.2.0
- 将SimpleNet仓库克隆到主目录
- 使用pip3安装仓库文档中列出的所有依赖包
- 下载MVTech数据集到主目录下新建的文件夹
- 在数据集目录执行命令
tar -xf mvtec_anomaly_detection.tar.xz解压归档文件 - 修改run.sh脚本的第1行和第10行,使其指向已下载的数据集路径
- 执行
bash run.sh命令 - 终端输出上述错误信息
环境信息
- WSL 20.04
- Python 3.8.10
- OpenCV 4.2.0(源码编译)
- Torch 1.12.1
- Torchvision 0.13.1
- numpy 1.22.4
已尝试操作
- 调试main.py代码,确认
@main.result_callback()之前的代码逻辑运行正常 - 找到仓库内相关问题记录,已知有用户解决该问题但无法理解具体操作步骤
解决方案
核心错误修复
该错误是由于使用了不兼容的fire库版本导致的。SimpleNet依赖的fire库在新版本中修改了装饰器的调用方式,导致main.result_callback()返回None,触发TypeError。
执行以下步骤修复:
- 卸载当前安装的fire库:
pip uninstall -y fire - 安装兼容的旧版本fire:
pip install fire==0.3.1 - 重新运行
bash run.sh脚本
消除Matplotlib警告
针对Matplotlib的缓存目录警告,可通过设置环境变量解决:
# 替换username为你的WSL用户名 export MPLCONFIGDIR=/home/username/.config/matplotlib mkdir -p $MPLCONFIGDIR chmod 755 $MPLCONFIGDIR
设置完成后再执行训练脚本,即可消除该警告。
内容的提问来源于stack exchange,提问作者mericgeren
相关产品推荐
相关产品推荐

