关于labelimg安装后在标注过程中闪退和死机的问题处理

labelimg安装后在标注过程中闪退和死机,并在控制台出现如下错误提示:

raceback (most recent call last): File "D:\dev\python3.12.0\Lib\site-packages\libs\canvas.py", line 530, in paintEvent p.drawLine(self.prev_point.x(), 0, self.prev_point.x(), self.pixmap.height()) 运行labelimg时候出现如下错误:TypeError: arguments did not match any overloaded call: drawLine(self, l: QLineF): argument 1 has unexpected type 'float' drawLine(self, line: QLine): argument 1 has unexpected type 'float' drawLine(self, x1: int, y1: int, x2: int, y2: int): argument 1 has unexpected type 'float' drawLine(self, p1: QPoint, p2: QPoint): argument 1 has unexpected type 'float' drawLine(self, p1: UnionQPointF, QPoint, p2: UnionQPointF, QPoint): argument 1 has unexpected type 'float'

经过查找资料发现是labelimg版本不能PQ5版本兼容出现的问题,具体的说是使用的 Python 版本较高(当前是 Python 3.12),而 LabelImg 这个工具在较新的 PyQt5 库中,绘图函数不再支持传入浮点数(float),必须强制转换为整数(int)。

具体处理的方法如下:

1. 修改 canvas.py 文件(解决核心报错)

根据报错提示,找到 D:\dev\python3.12.0\Lib\site-packages\libs\canvas.py 这个文件,用文本编辑器(如记事本、VS Code等)打开它。

找到第 530 行左右的代码:

p.drawLine(self.prev_point.x(), 0, self.prev_point.x(), self.pixmap.height())

将其修改为(在坐标数值外包裹 int() 进行强制转换):

p.drawLine(int(self.prev_point.x()), 0, int(self.prev_point.x()), int(self.pixmap.height()))

建议顺手修复同文件下的其他潜在报错

为了防止后续出现类似的闪退,建议同时检查并修改该文件中第 526 行和第 531 行的代码:

  • 第 526 行修改为:
    p.drawRect(int(left_top.x()), int(left_top.y()), int(rect_width), int(rect_height))
  • 第 531 行修改为:
    p.drawLine(0, int(self.prev_point.y()), int(self.pixmap.width()), int(self.prev_point.y()))

2. 修改 labelImg.py 文件(预防滚动闪退)

在高版本 Python 中,滚动鼠标滚轮时也容易触发类似的 float 类型报错。建议提前修复:

找到 D:\dev\python3.12.0\Lib\site-packages\labelImg\labelImg.py 这个文件并打开。

找到第 965 行左右(通常在 scroll_request 函数内)的代码:

  • bar.setValue(bar.value() + bar.singleStep() * units)

  • 将其修改为:

  • bar.setValue(int(bar.value() + bar.singleStep() * units))

  • 经过以上修改有效的解决上述问题。

相关推荐
梦帮科技2 小时前
从提示词到可复现音乐工作流:RNOISE 2.0 的 Prompt Engineering 架构
人工智能·python·mysql·ci/cd·架构·node.js·numpy
飞Link2 小时前
【Numpy】 第三部分:矩阵运算与线性代数(计算篇)
python·numpy
电商API_180079052472 小时前
电商平台数据分析实战_帖子
开发语言·爬虫·python·数据采集·京东
带多刺的玫瑰2 小时前
Leecode#35刷题之搜索插入位置
java·python·算法
QQ14220784492 小时前
IIS + wfastcgi 部署 Flask 应用实战:从连续 500 到稳定 200 的完整踩坑实录
python
传奇开心果编程2 小时前
【Rust入门知识点学与练】第36课:所有权——移动、借用、Copy、切片
开发语言·学习·rust
WiKiLeaks_successor2 小时前
Scipy库里的众数函数不严谨,我把它重构了。
python·scipy
傻啦嘿哟3 小时前
房产数据对比爬虫:同时爬取链家+贝壳+安居客,做房价横向对比
python
小静AI工程实验室3 小时前
JS 逆向接口 ID 变了?Python 与 Node.js 复现 JSON 大整数精度丢失
javascript·python·node.js
李航19833 小时前
用 DeepDraw 几何引擎开发建筑设计软件(五):创建选择工具
python·3d