Pyusb pythonshell说没有名为usb的模块,但linuxshell没有';T
我在找一些关于Pyubs的文件。发现了这一点,并试图使用伦纳特·雷内格罗的答案 空闲时python shell中的导入usb给了我以下错误:Pyusb pythonshell说没有名为usb的模块,但linuxshell没有';T,pyusb,python,Pyusb,Python,我在找一些关于Pyubs的文件。发现了这一点,并试图使用伦纳特·雷内格罗的答案 空闲时python shell中的导入usb给了我以下错误: Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> import usb ImportError: No module named 'usb' bash返回以下错误(我本来以为是因为我没有连接任何usb设备): 回溯(最近
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import usb
ImportError: No module named 'usb'
bash返回以下错误(我本来以为是因为我没有连接任何usb设备):
回溯(最近一次呼叫最后一次):
文件“first.py”,第6行,在
raise VALUERROR('未找到设备')
ValueError:找不到设备
这里发生了什么?那么我该如何阅读这些文档呢?总结上面的讨论,IDLE的python版本和默认的python shell显然是不同的。您为Python2.7.5安装了
pyusb
,而您希望在运行Python3.3.2的空闲设备上使用它
来解决这个问题
- 为python 3.3.2安装
pyusb
- 确保将Python2.7.5与IDLE一起使用。对于后者,您可以看看@justhalf所指的问题:
>>导入sys>>>打印(sys.version)
您可能想在空闲时运行脚本。毕竟我们已经知道Linux shell中使用的Python版本,我们只需要将其与IDLE中的版本进行比较。PythonShell-3.3.2+(默认值,2013年10月9日,14:50:09)[GCC 4.8.1]在官方页面上说pyusb在任何python版本>=2.4上运行这是正确的,但是安装Python2.7.5的某些包并不能自动使其适用于Python3.3.2。您必须分别为3.3.2安装相同的软件包。
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')
Traceback (most recent call last):
File "first.py", line 6, in <module>
raise ValueError('Device not found')
ValueError: Device not found