一切都很明显,如下面的图片和代码所示:
我想导入D:\pyusb-1.0.0a2\usb
中存在的模块,但我收到错误!
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 :(得分:5)
您需要将d:/pyusb-1.0.0a2/
附加到Python路径,不 d:/pyusb-1.0.0a2/usb/
。
正如您在尝试导入core
时所看到的那样,错误不再是您的导入失败,而是usb.core
模块无法导入{{1因为你的Python路径中没有usb.util
模块,只有里面的模块 usb
,例如usb
或core
。