【问题标题】:ImportError when running a script in a folder with pyd file/librarys在具有 pyd 文件/库的文件夹中运行脚本时出现 ImportError
【发布时间】:2018-04-02 22:17:57
【问题描述】:

我的脚本需要在包含其他 python 文件和库(.py、.pyd 等)的目录中运行,但与文件冲突,我猜测它来自与脚本相同目录中的文件 _ctypes.pyd:

C:\Users\Guest\AppData\Local\Programs\Python\Python35-32\python.exe "C:/Program Files (x86)/Program/script.py"
Traceback (most recent call last):
  File "C:/Program Files (x86)/Program/script.py", line 3, in <module>
    import ctypes
  File "C:\Users\Guest\AppData\Local\Programs\Python\Python35-32\lib\ctypes\__init__.py", line 7, in <module>
    from _ctypes import Union, Structure, Array
ImportError: dynamic module does not define module export function (PyInit__ctypes)

有没有办法解决这个问题?脚本需要能够在任何目录中运行而不会出错

【问题讨论】:

    标签: python python-3.x python-3.5 pyd


    【解决方案1】:
    import sys
    sys.path.insert(0, "/path/to/your/package_or_module")
    

    在导入任何库之前使用代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-09
      • 1970-01-01
      • 2014-06-11
      • 2021-08-03
      • 1970-01-01
      • 1970-01-01
      • 2017-10-07
      相关资源
      最近更新 更多