【问题标题】:Error trying to call the backend module in pyusb. "AttributeError: 'module' object has no attribute 'backend'"尝试在 pyusb 中调用后端模块时出错。 “AttributeError:‘模块’对象没有属性‘后端’”
【发布时间】:2014-04-11 23:00:18
【问题描述】:

我最近为这个项目安装了 pyusb,它正在尝试写入 USB LED Message Board 并收到此错误:

AttributeError: 'module' object has no attribute 'backend'

我不知道这是为什么,我检查了 pyusb 模块文件,它显然有一个名为“backend”的文件夹,里面有正确的文件。

这是我所有的代码:

import usb.core
import usb.util
import sys

backend = usb.backend.libusb01.get_backend(find_library=lambda C: "Users\absolute\Desktop\libusb-win32-bin-1.2.6.0\lib\msvc_x64")

#LED Display Message device identify
MessageDevice = usb.core.find(idVendor=0x1D34, idProduct=0x0013, backend=backend)

if MessageDevice is None:
    raise ValueError('LED Message Display Device could not be found.')

MessageDevice.set_configuration()





# get an endpoint instance
cfg = MessageDevice.get_active_configuration()
interface_number = cfg[(0,0)].bInterfaceNumber
print interface_number
alternate_settting = usb.control.get_interface(interface_number)
intf = usb.util.find_descriptor(
    cfg, bInterfaceNumber = interface_number,
    bAlternateSetting = alternate_setting
)

ep = usb.util.find_descriptor(
    intf,
    # match the first OUT endpoint
    custom_match = \
    lambda e: \
        usb.util.endpoint_direction(e.bEndpointAddress) == \
        usb.util.ENDPOINT_OUT
)

assert ep is not None

# write the data
ep.write('\x00\x06\xFE\xBA\xAF\xFF\xFF\xFF')

要关注的代码:

backend = usb.backend.libusb01.get_backend(find_library=lambda C: "Users\absolute\Desktop\libusb-win32-bin-1.2.6.0\lib\msvc_x64")

我还注意到在其他代码中人们根本没有后端。但是当我尝试删除代码的后端部分时,它会显示:

MessageDevice = usb.core.find(idVendor=0x1D34, idProduct=0x0013)
File "C:\Python27\lib\site-packages\usb\core.py", line 846, in find
raise ValueError('No backend available')
ValueError: No backend available

一些额外的信息:

  • Windows 8 64 位
  • Python 2.7
  • pyusb-1.0.0a2

【问题讨论】:

    标签: python python-2.7 module attributeerror pyusb


    【解决方案1】:

    我知道这个问题已经 4 个月了,但如果它有帮助,我认为您缺少导入声明:

    import usb.backend.libusb1
    

    更多详情请见https://github.com/walac/pyusb/blob/master/docs/tutorial.rst#specifying-libraries-by-hand

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-03
      • 2020-04-29
      • 2014-10-23
      • 2010-11-18
      相关资源
      最近更新 更多