【问题标题】:Why does importing usb.core work in the shell, but not in a new window?为什么导入 usb.core 在 shell 中有效,但在新窗口中无效?
【发布时间】:2013-07-12 21:27:55
【问题描述】:

我的问题是当我尝试在新窗口中导入 usb.coreusb 或仅在 shell 窗口之外的 usb.util 时。当我点击运行时,它会在 shell 窗口上显示

"ImportError: No module named core".

但是当我在 shell 窗口或 python 命令行中导入 usb 时,它工作正常!!

【问题讨论】:

    标签: python libusb pyusb


    【解决方案1】:

    您的 PYTHONPATH 在 shell 中的设置与在目标窗口中的设置不同。

    运行此代码以确保:

    import sys
    print sys.path
    

    在两个平台上进行比较。

    【讨论】:

    • 这是我在 shell 中得到的:['', 'C:\\Python27\\Lib\\idlelib', 'C:\\Windows\\system32\\python27.zip' , 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\ lib-tk', 'C:\\Python27', 'C:\\Python27\\lib\\site-packages', 'C:\\Python27\\lib\\site-packages\\wx-2.8-msw -unicode']
    • 这在一个新窗口中:['C:/Users/Martinez/Desktop', 'C:\\Python27\\Lib\\idlelib', 'C:\\Windows\\system32 \\python27.zip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C:\\ Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\lib\\site-packages', 'C:\\Python27\\lib\\site-packages\ \wx-2.8-msw-unicode'] 如何更改路径?
    • sys.path.append,或将其作为 PYTHONPATH 变量传递。 Windows 中的 Python 永远不会有趣。
    • 我改变了我的路径,但它仍然无法正常工作,只有 shell 窗口!我还能做什么???
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-12
    • 2015-09-12
    • 2011-07-19
    相关资源
    最近更新 更多