2014-09-02 75 views
1

一切都很明显,因为下面的图片和代码紧接着它: 我想导入一个模块,这个模块在D:\pyusb-1.0.0a2\usb中有,但我收到错误!为什么我不能导入这个模块

enter image description here

Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (Intel)] on win32 
Type "copyright", "credits" or "license()" for more information. 
>>> import sys 
>>> sys.path.append('d:\pyusb-1.0.0a2\usb') 
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 16-17: truncated \uXXXX escape 
>>> sys.path.append('d:/pyusb-1.0.0a2/usb') 
>>> from usb import core 
Traceback (most recent call last): 
    File "<pyshell#3>", line 1, in <module> 
    from usb import core 
ImportError: No module named 'usb' 

>>> import core 
Traceback (most recent call last): 
    File "<pyshell#4>", line 1, in <module> 
    import core 
    File "d:/pyusb-1.0.0a2/usb\core.py", line 44, in <module> 
    import usb.util as util 
ImportError: No module named 'usb' 

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

尝试'sys.path.append('d:\\ pyusb-1.0.0a2 \\ usb')' – klasske 2014-09-02 09:14:43

+1

@klasske:不,这不是问题。 OP(和你)误解了'sys.path'搜索路径的工作方式。 – 2014-09-02 09:16:14

+1

@MartijnPieters我正在查看第一个错误,这是由于\ u' – klasske 2014-09-02 09:21:28

回答

5

您需要添加d:/pyusb-1.0.0a2/到你的Python路径,d:/pyusb-1.0.0a2/usb/

正如你可以看到当试图导入core错误不再是导入失败,但该usb.core模块没能导入usb.util因为没有usb模块在你的Python路径可用,只有模块内部usb,如coreutil

+0

转义造成的正如您在问题中看到的,我已经添加了路径! – TheGoodUser 2014-09-02 09:16:47

+0

是的,但从路径中移除'usb'。 – 2014-09-02 09:17:16

+2

@TheGoodUser:不,你没有。你追加了路径*加上'usb' *。删除包名称。 – 2014-09-02 09:17:26

相关问题