没有名为usb.core的模块

问题描述:

如何在下面提到的程序中删除此错误? iI'm得到的错误是没有名为usb.core的模块

ImportError: No module named usb.core 

,我的代码是:

import usb.core 
import usb.util 

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

# was it found? 
if dev is None: 
    raise ValueError('Device not found') 

# set the active configuration. With no arguments, the first 
# configuration will be the active one 
dev.set_configuration() 

# get an endpoint instance 
cfg = dev.get_active_configuration() 
intf = cfg[(0,0)] 

ep = usb.util.find_descriptor(
    intf, 
    # match the first OUT endpoint 
    custom_match = \ 
    lambda e: \ 
     usb.util.endpoint_direction(e.bEndpointAddress) == \ 
     usb.util.ENDPOINT_OUT) 

assert ep is not None 

# write the data 
ep.write('test') 
+0

你在什么操作系统下运行?一般来说,你安装了PyUSB吗? – 2014-10-05 14:39:09

+0

检查此SO问题:[链接](http://*.com/questions/24790690/importerror-no-module-named-usb-core-working-in-terminal-not-in-eclipse) – Joe 2014-10-05 14:40:11

+0

操作系统是Windows 8 64位,是的,我已经安装,但即时得到错误: 回溯(最近呼叫最后): 文件“C:\用户\ RAHUL \桌面\ python程序\ USBsample.py”,第5行,在 dev = usb.core.find(idVendor = 0xfffe,idProduct = 0x0001) 文件“C:\ Python27 \ lib \ site-packages \ usb \ core.py”,第864行,找到 raise ValueError('No backend可用') ValueError:没有后端可用 – 2014-10-05 15:04:18

OS is windows 8 64-bit [...] ValueError: No backend available

请允许我来翻译:你忘了安装正确的USB驱动程序。

USB设备需要驱动程序才能在Windows中工作。有关详细信息,请参阅PyUSB website,并使用Zadig为您生成并安装驱动程序(例如LibUSB-Win32)。该程序负责Windows 8希望为您的驱动程序inf文件查看的证书。

Btw:您应该用于USB开发的VID是0x4242