You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

运行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。

执行以下步骤修复:

  1. 卸载当前安装的fire库:
    pip uninstall -y fire
    
  2. 安装兼容的旧版本fire:
    pip install fire==0.3.1
    
  3. 重新运行bash run.sh脚本

消除Matplotlib警告

针对Matplotlib的缓存目录警告,可通过设置环境变量解决:

# 替换username为你的WSL用户名
export MPLCONFIGDIR=/home/username/.config/matplotlib
mkdir -p $MPLCONFIGDIR
chmod 755 $MPLCONFIGDIR

设置完成后再执行训练脚本,即可消除该警告。

内容的提问来源于stack exchange,提问作者mericgeren

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 21:37:19