Error trying to call the backend module in pyusb. “AttributeError: 'module' object has no attribute 'backend'”

依然范特西╮ 提交于 2021-01-04 09:01:58

问题


I recently installed pyusb for this project, which is trying to attempt at writing to a USB LED Message Board and received this error:

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

I don't know why this is, I checked the pyusb module files and it clearly has a folder named "backend" and inside has the correct files.

Here's all of my code:

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')

Code to focus on:

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

Also I've noticed in other code people don't have the backend at all. But when I try to remove the backend part of my code it displays:

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

Some extra info:

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

回答1:


I know this question is 4 months old, but in case it helps I think you're missing an import statement:

import usb.backend.libusb1

See https://github.com/walac/pyusb/blob/master/docs/tutorial.rst#specifying-libraries-by-hand for more details.



来源:https://stackoverflow.com/questions/22273100/error-trying-to-call-the-backend-module-in-pyusb-attributeerror-module-obje

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!