我正在尋找pyusb上的一些文檔。發現這link並試圖使用Lennart Renegro的答案。Python shell說沒有模塊命名爲usb但linux shell不是
在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和你的bash shell的python版本是一樣的嗎? –
@ Chiel92我不確定。 Python shell的第一行說Python 3.3.2+(默認,2013年10月9日14:50:09) [GCC 4.8.1]在linux上。我不知道我的bash shell的版本,也不知道如何檢查它。有沒有可以運行的命令來查看? –
在您的shell運行:>>> import sys >>> print(sys.version)' –