No module named usb.core

Rahul Dhiman picture Rahul Dhiman · Oct 5, 2014 · Viewed 11.5k times · Source

How can I remove this error in the below mentioned program? The error iI'm getting is

ImportError: No module named usb.core

and my code is:

import usb.core
import usb.util

# find our device
dev = usb.core.find(idVendor=0xfffe, idProduct=0x0001)

# was it found?
if dev is None:
    raise ValueError('Device not found')

# set the active configuration. With no arguments, the first
# configuration will be the active one
dev.set_configuration()

# get an endpoint instance
cfg = dev.get_active_configuration()
intf = cfg[(0,0)]

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

Answer

Turbo J picture Turbo J · Oct 6, 2014

OS is windows 8 64-bit [...] ValueError: No backend available

Allow me to translate: You forgot to install the correct USB driver.

USB devices need a driver to work in Windows. Look at PyUSB website for details, and use Zadig to generate and install the driver (e.g. LibUSB-Win32) for you. This program takes care of the certificate that Windows 8 wants to see for your drivers inf file.

Btw: The VID you should use for USB development is 0x4242.