使用pyd文件/ librarys在文件夹中运行脚本时的ImportError

时间:2017-10-22 06:34:46

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

我的脚本需要在包含其他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)

有解决方法吗?该脚本需要能够在任何目录中运行而不会出现错误

1 个答案:

答案 0 :(得分:0)

import sys
sys.path.insert(0, "/path/to/your/package_or_module")

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