获取DLL以与依赖项通信

2024-09-26 22:13:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从Python加载DLL,但是得到WindowsError: [Error 126] The specified module could not be found.

import ctypes
my_dll = "C:/smt/toolbox/dlls/NMSim_Libraries.dll"
nmsim = ctypes.cdll.LoadLibrary(my_dll)

当我使用Dependency Walker时,它声明缺少3个依赖项,它们都在路径中: “C:\Users\skeyel\AppData\Local\Continuum\Anaconda2\Lib\site packages\numpy\core”

我尝试使用以下方法将此路径添加到系统路径:

^{pr2}$

但这并没有解决问题。如何使.dll与依赖项通信?在

注意事项:

  1. 我的电脑上有两个Python安装:ArcGIS附带的2.7.8和Anaconda附带的2.7.11。它运行良好时,运行通过Spyder IDE的水蟒安装。

  2. 它在我的笔记本电脑上运行良好(在2.7.8和2.7.11上)。

  3. 我根据以下建议检查和/或尝试了各种方法: WindowsError: [Error 126] The specified module could not be found

    3a.dll存在并且到dll的路径是正确的,因为当我复制和粘贴完全相同的代码时,它适用于一个版本

    3b.DLL和Python都设置为32位(注意:操作系统是64位的)。使用import platform后跟platform.architecture()将两个版本都作为32位。在

    3c.我尝试过调整sys.path以包括两个安装之间的相同路径

    我尝试了os.chdir()切换到.dll目录,然后只按名称加载dll,没有路径信息

    3e.我已尝试将列出的缺少的依赖项复制并粘贴到与.dll相同的文件夹中

  4. 我试着复制、粘贴和运行从这里选择的答案(最小修改)代码:Python | accessing dll using ctypes

以下是完整的回溯:

Runtime error 
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\skeyel\AppData\Local\Continuum\Anaconda2\Lib\ctypes\__init__.py", line 443, in LoadLibrary
    return self._dlltype(name)
File "C:\Users\skeyel\AppData\Local\Continuum\Anaconda2\Lib\ctypes\__init__.py", line 365, in __init__
    self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found

我好像错过了一些简单的东西-有人知道是什么吗?在

非常感谢。在


Tags: the路径noterrorbectypesusersappdata

热门问题