Question

I was looking for some documetation on pyusb . Found this link and tried to use Lennart Renegro's answer.

import usb in python shell on IDLE gave me the following error:

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import usb
ImportError: No module named 'usb'

However, I ran this program using python first.py on bash:

import usb

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

if dev is None:
    raise ValueError('Device not found')

dev.set_configuration()

cfg = dev.get_active_configuration()

interface_number = cfg[(0,0)].bInterfaceNumber
alternate_setting = usb.control.get_interface(interface_number)
intf = usb.util.find_descriptor(cfg, bInterfaceNumber = interface_number, bAlternateSetting = alternate_setting)

ep = usb.util.find.descriptor(intf, custom_match = lambda e: usb.util.endpoint_direction(e.bEndpointAddress) == usb.util.ENDPOINT_OUT)
assert ep is not None

ep.write('test')

and bash return the following error(which I was expecting because I hadn't connected any usb devices atm):

Traceback (most recent call last):
  File "first.py", line 6, in <module>
    raise ValueError('Device not found')
ValueError: Device not found

What is happening here? And how do I read those docs?

Was it helpful?

Solution

Summarizing the discussion above, apparently the python versions of IDLE and the default python shell are different. You installed pyusb for python 2.7.5, while you want to use it on IDLE which runs python 3.3.2.

To fix this problem, either

  • install pyusb for python 3.3.2
  • make sure to use python 2.7.5 with IDLE. For the latter you can have a look at the question @justhalf pointed to: Python IDLE: Change Python Version
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top