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()))
相关推荐
袁袁袁袁满1 小时前
OpenAI SDK集成亮数据网页解锁器实现自动化爬虫
爬虫·python·ai·网络爬虫·爬虫实战·自动化爬虫·ai爬虫
哈哈不让取名字1 小时前
使用Fabric自动化你的部署流程
jvm·数据库·python
仰望星空@脚踏实地2 小时前
Python 中subprocess.getstatusoutput(cmd) 函数注入命令风险分析
python·datakit·getstatusoutput
深蓝电商API2 小时前
Scrapy 自定义命令与扩展:打造专属爬虫工具
爬虫·python·scrapy
郝学胜-神的一滴2 小时前
机器学习数据预处理:深入理解标准化与sklearn的StandardScaler
开发语言·人工智能·python·程序人生·机器学习·sklearn
@fai2 小时前
[特殊字符] 在 PyQt6 中实现 Photoshop 风格的“橡皮擦”光标:高性能、不随缩放变形、精准跟随鼠标
图像处理·python·pyqt·photoshop
山风wind2 小时前
设计模式-访问者模式详解
python·设计模式·访问者模式
weixin_462446232 小时前
使用 pip3 一键卸载当前环境中所有已安装的 Python 包(Linux / macOS / Windows)
linux·python·macos
2501_944526422 小时前
Flutter for OpenHarmony 万能游戏库App实战 - 收藏功能实现
android·java·开发语言·javascript·python·flutter·游戏