7

So I installed Pyusb 1.0.0-alpha-1
Under Windows, I cannot get any handles to usb devices.

>>> import usb.core
>>> print usb.core.find()
None

I do have 1 usb device plugged in(idVendor=0x04d8, idProduct=0x0042), and I tried usb.core.find(idVendor=0x04d8, idProduct=0x0042) but that failed too.

Under Ubuntu, with the same versions of pyusb and python (2.6), I am able to successfully find my device with that code, and communicate with it.

So how can I get pyusb to find usb devices on Windows 7?

Ponkadoodle
  • 5,777
  • 5
  • 38
  • 62
  • This might be a stupid question, but are the drivers installed correctly? It looks like PyUSB has dependencies on libusb. See https://github.com/karlp/karlnet/tree/usbmaster/producers/pyhid/ – Brian Lyttle Mar 22 '11 at 00:47
  • 1
    @BrianLy That was actually a great question to ask, thanks! I did a little bit of tinkering, and found that the libusb0.1 backend was being loaded instead. It turns out I was using 32bit python and had installed the 64 bit libusb1.0 dll. I replaced that with the 32 bit version, and now usb.core.find() works. – Ponkadoodle Mar 22 '11 at 01:34
  • However, I have other errors now. When I try `device.detach_kernel_header(0)`, I get `USBError: Operation not supported or unimplemented on this platform`. – Ponkadoodle Mar 22 '11 at 01:35
  • Detaching the kernel driver is only implemented on Linux. I guess you are trying to access a HID device, aren't you? I've heard that libusb isn't the best choice then. Try [HIDAPI](http://www.signal11.us/oss/hidapi/) instead but I don't know if there is a python binding available for it. – kayahr Mar 22 '11 at 21:46

3 Answers3

5

See Turbo J's answer. To install the USB driver libusb for your device I found two options:

  • Use libusb-win32's inf-wizard.exe to create the INF file and then use install-filter-win.exe to install libusb as driver for your device.

  • Use zadig (simpler)

    • if no device is shown, Options > List All Devices
    • select libusb-win32 as driver to be installed
Community
  • 1
  • 1
handle
  • 5,859
  • 3
  • 54
  • 82
4

Libusb requires you to install a special driver for every device you want to use it with. That usually requires you to write an .inf file containing the USB IDs of the device. Only if the driver and inf file are installed libusb will be able to "see" your device.

Turbo J
  • 7,563
  • 1
  • 23
  • 43
  • 5
    Where does the inf file need to live? I've done as you recommend at am still getting the same result as OP – Chris Apr 03 '13 at 15:19
1

Exactly the same was happening to me in Windows 10 running Python 3.9. According to the installation instructions of PyUSB you need to manually install libusb on Windows. For this I followed the instructions in the README file shipped with the Windows files (i.e. manually copied libusb-1.0.dll and libusb-1.0.dll.a into C:\Windows\System32) and now PyUSB is listing the devices with

import usb.core
import usb.util

list(usb.core.find(find_all=True))
user171780
  • 2,243
  • 1
  • 20
  • 43