简体   繁体   中英

Why I can't import this module

Everything is obvious as the below image and the codes followed it : I want to import a module that phycially there is in the D:\\pyusb-1.0.0a2\\usb\u003c/code> , but I receive errors!

在此处输入图片说明

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'
>>> 

You need to append d:/pyusb-1.0.0a2/ to your Python path, and not d:/pyusb-1.0.0a2/usb/ .

As you can see when trying to import core the error is no longer that your import failed, but that the usb.core module did not manage to import usb.util since there's no usb module available in your Python path, only modules inside usb , such as core or util .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM