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

Windows11下用brother_ql库打印图片报错:Operation not supported

问题场景与代码

在Windows 11系统中,尝试使用Python的brother_ql库为Brother QL-560打印机打印图片,已完成以下配置:

  • 安装libusb-1.0.20,将MS64/dll添加到PATH变量,并把libusb-1.0.dll复制到System32目录
  • Brother QL-560已安装官方驱动,可在P-Touch Editor中正常打印

使用的代码如下:

from PIL import Image
from brother_ql.conversion import convert
from brother_ql.backends.helpers import send, discover
from brother_ql.raster import BrotherQLRaster
import logging

logging.basicConfig(level=logging.DEBUG)

image = Image.open(r'.\screenshot.png')
size = (720, 1008)
image = image.resize(size)

backend = 'pyusb'
#find printer
#print(discover(backend))
printer = 'usb://0x04f9:0x2027'
model = 'QL-560'

qlr = BrotherQLRaster(model)
qlr.exception_on_warning = True

instructions = convert(
        qlr=qlr, 
        images=[image],
        label='62', 
        rotate='90',    # 'Auto', '0', '90', '270'
        threshold=70.0,    # Black and white threshold in percent.
        dither=False, 
        compress=False, 
        dpi_600=False, 
        hq=True,
        cut=True
)

send(instructions=instructions, printer_identifier=printer, backend_identifier=backend, blocking=True)

运行代码后抛出错误:

deprecation warning: brother_ql.devicedependent is deprecated and will be removed in a future release
WARNING:brother_ql.conversion:Need to resize the image...
DEBUG:brother_ql.raster:raster_image_size: 720x497
Traceback (most recent call last):
  File "C:\Users\User\PycharmProjects\labelCreator\listUSB.py", line 42, in <module>
    send(instructions=instructions, printer_identifier=printer, backend_identifier=backend, blocking=True)
  File "C:\Users\User\PycharmProjects\labelCreator\venv\lib\site-packages\brother_ql\backends\helpers.py", line 57, in send
    printer = BrotherQLBackend(printer_identifier)
  File "C:\Users\User\PycharmProjects\labelCreator\venv\lib\site-packages\brother_ql\backends\pyusb.py", line 101, in __init__
    self.dev.set_configuration()
  File "C:\Users\User\PycharmProjects\labelCreator\venv\lib\site-packages\usb\core.py", line 915, in set_configuration
    self._ctx.managed_set_configuration(self, configuration)
  File "C:\Users\User\PycharmProjects\labelCreator\venv\lib\site-packages\usb\core.py", line 113, in wrapper
    return f(self, *args, **kwargs)
  File "C:\Users\User\PycharmProjects\labelCreator\venv\lib\site-packages\usb\core.py", line 158, in managed_set_configuration
    self.managed_open()
  File "C:\Users\User\PycharmProjects\labelCreator\venv\lib\site-packages\usb\core.py", line 113, in wrapper
    return f(self, *args, **kwargs)
  File "C:\Users\User\PycharmProjects\labelCreator\venv\lib\site-packages\usb\core.py", line 131, in managed_open
    self.handle = self.backend.open_device(self.dev)
  File "C:\Users\User\PycharmProjects\labelCreator\venv\lib\site-packages\usb\backend\libusb1.py", line 804, in open_device
    return _DeviceHandle(dev)
  File "C:\Users\User\PycharmProjects\labelCreator\venv\lib\site-packages\usb\backend\libusb1.py", line 652, in __init__
    _check(_lib.libusb_open(self.devid, byref(self.handle)))
  File "C:\Users\User\PycharmProjects\labelCreator\venv\lib\site-packages\usb\backend\libusb1.py", line 600, in _check
    raise NotImplementedError(_strerror(ret))
NotImplementedError: Operation not supported or unimplemented on this platform

Process finished with exit code 1

疑问:遗漏了什么配置?是否存在驱动不兼容的问题?

解决方案

这个错误的核心原因是Windows系统中,官方打印机驱动已占用USB设备,导致libusb/pyusb无法获取设备访问权限,以下是两种可行的解决途径:

途径1:改用Windows专属Backend(推荐)

brother_ql库提供了针对Windows的原生backend,无需依赖libusb,直接修改代码即可:

  1. 将代码中的backend = 'pyusb'改为backend = 'windows'
  2. 取消注释print(discover(backend))这一行,运行代码获取正确的打印机标识符(可能是类似'usb://0x04f9:0x2027'或者打印机的系统显示名称)
  3. 将获取到的标识符替换到printer变量中,重新运行代码

途径2:替换打印机驱动为libusb兼容版本(需权衡)

如果坚持使用pyusb backend,需要将官方驱动替换为libusb-win32:

  • 使用Zadig工具,找到Brother QL-560设备,将其驱动替换为libusb-win32
  • 注意:替换后官方P-Touch Editor将无法使用该打印机,若需要恢复,需在设备管理器中手动换回官方驱动

额外代码优化建议

  • 无需手动resize图片,convert函数会根据标签尺寸自动调整,可删除手动resize的代码行,避免尺寸不匹配的警告
  • 保持qlr.exception_on_warning = True,便于及时发现配置问题

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 07:45:00