为什么我无法导入此模块

时间:2014-09-02 09:12:11

标签: python python-3.x

一切都很明显,如下面的图片和代码所示: 我想导入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'
>>> 

1 个答案:

答案 0 :(得分:5)

您需要将d:/pyusb-1.0.0a2/附加到Python路径, d:/pyusb-1.0.0a2/usb/

正如您在尝试导入core时所看到的那样,错误不再是您的导入失败,而是usb.core模块无法导入{{1因为你的Python路径中没有usb.util模块,只有里面的模块 usb,例如usbcore