1

我正在寻找一些关于 pyusb 的文档。找到此链接并尝试使用 Lennart Renegro 的答案。

import usb在空闲的python shell中给了我以下错误:

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

python first.py但是,我使用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')

并且 bash 返回以下错误(这是我所期待的,因为我没有连接任何 USB 设备 atm):

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

这里发生了什么?我如何阅读这些文档?

4

1 回答 1

0

总结上面的讨论,显然 IDLE 的 python 版本和默认的 python shell 是不同的。您pyusb为 python 2.7.5 安装,而您想在运行 python 3.3.2 的 IDLE 上使用它。

要解决此问题,要么

于 2014-03-01T14:25:08.950 回答