[英]Python shell says no module named usb but linux shell doesn't
我正在寻找有关pyusb的文档。 找到了此链接,并尝试使用Lennart Renegro的答案。
在IDLE的python shell中import usb
给了我以下错误:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import usb
ImportError: No module named 'usb'
但是,我在bash上使用python first.py
运行了该程序:
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
这是怎么回事 我该如何阅读这些文档?
总结以上讨论,显然IDLE的python版本和默认的python shell不同。 您已为python 2.7.5安装了pyusb
,而您想在运行python 3.3.2的IDLE上使用它。
要解决此问题,
pyusb
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.