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()))
相关推荐
wj3055853787 小时前
课程 9:模型测试记录与 Prompt 策略
linux·人工智能·python·comfyui
星寂樱易李7 小时前
iperf3 + Python-- 网络带宽、网速、网络稳定性
开发语言·网络·python
qingfeng154157 小时前
企业微信机器人开发:如何实现自动化与智能运营?
人工智能·python·机器人·自动化·企业微信
彦为君10 小时前
Agent 安全:从权限提示到沙箱隔离
python·ai·ai编程
PILIPALAPENG11 小时前
Python 语法速成指南:前端开发者视角(JS 类比版)
前端·人工智能·python
用户83562907805112 小时前
Python 操作 PowerPoint 页眉与页脚指南
后端·python
枫叶林FYL13 小时前
项目九:异步高性能爬虫与数据采集中枢 —— 基于 Crawl<sub>4</sub>AI 与 Playwright 的现代化数据采集平台 项目总览
爬虫·python·深度学习·wpf
猫猫的小茶馆13 小时前
【Python】函数与模块化编程
linux·开发语言·arm开发·驱动开发·python·stm32
Miss_min13 小时前
128K长序列数据生成
开发语言·python·深度学习