windows系统安装labelimg按“W”键报错

labelimg按"W"键报错

E:\cn\yolo>labelImg

QMimeDatabase: Error loading internal MIME data

An error has been encountered at line 1 of <internal MIME data>: Premature end of document.:

qt.gui.icc: Unsupported ICC profile class 70727472

Traceback (most recent call last):

File "D:\conda\Lib\site-packages\labelImg\labelImg.py", line 965, in scroll_request

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

~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

TypeError: setValue(self, a0: int): argument 1 has unexpected type 'float'

解决方法:

新建fix_all_issues.py

复制代码
python fix_all_issues.py

import os
import re

def fix_labelimg_file():
    """修复 labelImg.py 中的所有类型转换问题"""
    labelimg_path = r"D:\conda\envs\labelimg\lib\site-packages\labelImg\labelImg.py"
    
    print(f"正在修复: {labelimg_path}")
    
    # 读取文件
    with open(labelimg_path, 'r', encoding='utf-8') as f:
        content = f.read()
    
    # 备份
    backup_path = labelimg_path + '.backup'
    with open(backup_path, 'w', encoding='utf-8') as f:
        f.write(content)
    print(f"已创建备份: {backup_path}")
    
    # 修复规则
    fixes = [
        # 1. 滚动问题(第965行)
        (r'(bar\.setValue\(bar\.value\(\) \+ bar\.singleStep\(\) \* units\))',
         r'int(\1)'),
        
        # 2. 直接修复 setValue 调用
        (r'self\.zoom_widget\.setValue\(value\)',
         r'self.zoom_widget.setValue(int(value))'),
        
        (r'self\.zoom_widget\.setValue\(([^)]+)\)',
         r'self.zoom_widget.setValue(int(\1))'),
        
        # 3. 修复 set_zoom 调用
        (r'self\.set_zoom\(self\.zoom_widget\.value\(\) \+ increment\)',
         r'self.set_zoom(int(self.zoom_widget.value() + increment))'),
        
        # 4. 修复所有 setValue 调用(通用)
        (r'(\w+)\.setValue\(([^)]+)\)',
         r'\1.setValue(int(\2))'),
        
        # 5. 确保所有 QSlider/QSpinBox 的 setValue 都使用整数
        (r'(self\.\w+_widget)\.setValue\(([^)]+)\)',
         r'\1.setValue(int(\2))'),
    ]
    
    # 应用修复
    for pattern, replacement in fixes:
        new_content, count = re.subn(pattern, replacement, content)
        if count > 0:
            print(f"  修复了 {count} 处: {pattern[:60]}...")
            content = new_content
    
    # 写回文件
    with open(labelimg_path, 'w', encoding='utf-8') as f:
        f.write(content)
    
    print("✓ labelImg.py 修复完成")

def fix_canvas_file():
    """修复 canvas.py 中的所有绘图问题"""
    canvas_path = r"D:\conda\envs\labelimg\lib\site-packages\libs\canvas.py"
    
    print(f"\n正在修复: {canvas_path}")
    
    # 读取文件
    with open(canvas_path, 'r', encoding='utf-8') as f:
        content = f.read()
    
    # 备份
    backup_path = canvas_path + '.backup'
    with open(backup_path, 'w', encoding='utf-8') as f:
        f.write(content)
    print(f"已创建备份: {backup_path}")
    
    # 修复所有绘图方法的参数
    # 通用模式:将方法调用的浮点数参数转换为整数
    content = re.sub(
        r'p\.(drawRect|drawLine|drawEllipse)\(([^)]+)\)',
        lambda m: convert_params(m.group(0), m.group(1)),
        content
    )
    
    # 写回文件
    with open(canvas_path, 'w', encoding='utf-8') as f:
        f.write(content)
    
    print("✓ canvas.py 修复完成")

def convert_params(match_str, method_name):
    """将绘图方法的参数转换为整数"""
    import re
    
    # 提取参数部分
    params_match = re.search(r'\((.*)\)', match_str)
    if not params_match:
        return match_str
    
    params = params_match.group(1)
    
    # 分割参数
    param_list = [p.strip() for p in params.split(',')]
    
    # 转换每个参数为整数
    converted_params = []
    for param in param_list:
        # 如果参数以 .x() .y() .width() .height() 结尾,转换为整数
        if any(suffix in param for suffix in ['.x()', '.y()', '.width()', '.height()']):
            param = f'int({param})'
        # 如果参数是数字或包含数学运算
        elif re.search(r'[\+\-\*/]', param):
            param = f'int({param})'
        # 其他情况保持不变
        converted_params.append(param)
    
    return f'p.{method_name}({", ".join(converted_params)})'

def main():
    print("=" * 60)
    print("开始修复 LabelImg 所有类型转换问题")
    print("=" * 60)
    
    fix_labelimg_file()
    fix_canvas_file()
    
    print("\n" + "=" * 60)
    print("所有修复完成!")
    print("=" * 60)
    print("\n现在可以正常运行 labelImg 了")
    print("已知问题:qt.gui.icc 警告可以安全忽略")

if __name__ == "__main__":
    main()

下面不用再看!

windows电脑训练

复制代码
python yolo_runner2.py --mode train --model "E:/cn/yolo/weights/yolov12x.pt" --data "E:/cn/yolo/datasets/260120_5/data.yaml" --epochs 30 --imgsz 1280 --batch 2 --workers 8 --rect --cache --cos_lr --device cpu --lr0 0.0012 --optimizer SGD --close_mosaic 50 --patience 100 --project "E:/cn/yolo/output" --name 260120_5train

直接修改文件的方法

根据错误信息,文件在:
D:\conda\envs\labelimg\lib\site-packages\libs\canvas.py

使用任意文本编辑器打开文件,比如:

复制代码
notepad "D:\conda\envs\labelimg\lib\site-packages\libs\canvas.py"

步骤2:找到并修改第530行

在文件中搜索 drawLine(self.prev_point.x(),找到类似这样的代码块:

通常在 paintEvent 方法中

def paintEvent(self, event):

... 前面的代码 ...

if self.prev_point and not self.out_of_pixmap(self.prev_point):

p.setPen(QPen(QColor(0, 0, 0), 1, Qt.DotLine))

p.drawLine(self.prev_point.x(), 0, self.prev_point.x(), self.pixmap.height()) # 第530行

p.drawLine(0, self.prev_point.y(), self.pixmap.width(), self.prev_point.y()) # 第531行

... 后面的代码 ...

步骤3:进行修改

修改前:

复制代码
p.drawLine(self.prev_point.x(), 0, self.prev_point.x(), self.pixmap.height())
p.drawLine(0, self.prev_point.y(), self.pixmap.width(), self.prev_point.y())

修改后:

复制代码
p.drawLine(int(self.prev_point.x()), 0, int(self.prev_point.x()), int(self.pixmap.height()))
p.drawLine(0, int(self.prev_point.y()), int(self.pixmap.width()), int(self.prev_point.y()))
相关推荐
m0_7485548127 分钟前
golang如何实现用户订阅偏好管理_golang用户订阅偏好管理实现总结
jvm·数据库·python
smj2302_796826521 小时前
解决leetcode第3911题.移除子数组元素后第k小偶数
数据结构·python·算法·leetcode
阿正呀2 小时前
Redis怎样实现本地缓存的高效失效通知
jvm·数据库·python
2501_901200532 小时前
mysql如何设置InnoDB引擎参数_优化innodb_buffer_pool
jvm·数据库·python
_.Switch2 小时前
东方财富股票数据JS逆向:secids字段和AES加密实战
开发语言·前端·javascript·网络·爬虫·python·ecmascript
Mr_sst2 小时前
Claude Code 部署与使用保姆级教程(2026 最新)
python·ai
瞎某某Blinder2 小时前
DFT学习记录[6]基于 HES06的能带计算+有效质量计算
python·学习·程序人生·数据挖掘·云计算·学习方法
m0_495496413 小时前
mysql处理复杂SQL性能_InnoDB优化器与MyISAM差异
jvm·数据库·python
forEverPlume4 小时前
PHP怎么使用Eloquent Attribute Composition属性组合_Laravel通过组合构建复杂属性【方法】
jvm·数据库·python
Aleeeeex4 小时前
RAG 那点事:从 8 份企业文档到能用的问答系统,全过程拆给你看
人工智能·python·ai编程