2

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')
Bill Lynch
  • 80,138
  • 16
  • 128
  • 173
Rahul Dhiman
  • 21
  • 1
  • 1
  • 3
  • 1
    What operating system are you running under? And in general, have you installed PyUSB? – Bill Lynch Oct 05 '14 at 14:39
  • Check this SO question: [link](http://stackoverflow.com/questions/24790690/importerror-no-module-named-usb-core-working-in-terminal-not-in-eclipse) – Johny Oct 05 '14 at 14:40
  • OS is windows 8 64-bit and yes i have installed but i m now getting errors: Traceback (most recent call last): File "C:\Users\RAHUL\Desktop\python progrms\USBsample.py", line 5, in dev = usb.core.find(idVendor=0xfffe, idProduct=0x0001) File "C:\Python27\lib\site-packages\usb\core.py", line 864, in find raise ValueError('No backend available') ValueError: No backend available – Rahul Dhiman Oct 05 '14 at 15:04

3 Answers3

1

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.

Turbo J
  • 7,563
  • 1
  • 23
  • 43
0

For error:

C:\Users\RAHUL\Desktop\python progrms\USBsample.py, line 5, in <module>
dev = usb.core.find(idVendor=0xfffe, idProduct=0x0001) File "C:\Python27\lib\site-
packages\usb\core.py", line 864, in find raise ValueError('No backend available')
ValueError: No backend available

Download and install libusb-win32-devel-filter-1.2.6.0.exe. It should work.

Reza Azimi
  • 56
  • 9
0
python -m pip install pyusb libusb

Fixed this for me.

Samuel
  • 8,063
  • 8
  • 45
  • 41