WindowsError: [Error 126] 加载带有 ctypes 的 DLL 时 [英] WindowsError: [Error 126] when loading a DLL with ctypes

查看:106
本文介绍了WindowsError: [Error 126] 加载带有 ctypes 的 DLL 时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这在带有 Python 2.7 的 Windows 7 上运行良好:

This works fine on Windows 7 with Python 2.7:

lib = ctypes.cdll.LoadLibrary('prov_means')
provmeans = lib.provmeans  

库 prov_means.DLL 在我的工作目录中.它导出一个简单、独立的 C 函数 provmeans(),没有依赖项.

The library prov_means.DLL is in my working directory. It exports a simple, stand-alone C function provmeans() with no dependencies.

当我在 Windows XP 和 Python 2.7 上尝试同样的事情时,我得到

When I try the same thing on Windows XP and Python 2.7 I get

Traceback (most recent call last):
  File "D:pythonAuxilsrcauxil.py", line 130, in <module>
    lib = ctypes.cdll.LoadLibrary('prov_means')
  File "C:Python27libctypes\__init__.py", line 431, in LoadLibrary
    return self._dlltype(name)
  File "C:Python27libctypes\__init__.py", line 353, in __init__
    self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found 

我尝试将 DLL 复制到 WindowsSystem32 并输入完整路径名

I have tried copying the DLL to WindowsSystem32 and also entering the full path name

"d:\python\auxil\src\prov_means"

带有和不带有.DLL"扩展名.没有任何效果.

with and without the ".DLL" extension. Nothing works.

推荐答案

错误 126 是无法找到依赖 DLL 时出现的错误.这有两个明显的原因:

Error 126 is what you get when a dependent DLL can not be found. There are two obvious causes for this:

  1. 未找到您的 DLL.
  2. 您的 DLL 依赖于其他找不到的 DLL.

我怀疑选项 1 是问题所在,但无论如何我想我可能会使用该 DLL 的完整路径来确定.

I doubt that option 1 is the problem but in any case I think I would probably be using a full path to that DLL to be sure.

因此剩下选项 2,最常见的原因是您的目标机器没有安装 C++ 运行时.在目标机器上安装 C++ 运行时,或使用静态链接,/MT,在构建 DLL 时,这样您就不需要重新分发运行时.

So that leaves option 2 and the most common cause for that is that your target machine does not have the C++ runtime installed. Either install the C++ runtime on your target machine, or use static linking, /MT, when building your DLL so that you do not need to redistribute the runtime.

可能,在您开发 DLL 的机器上,您已经安装了 C++ 编译器并为您安装了运行时.在代码失败的目标机器上,您没有安装编译器,因此不存在运行时.

Probably, on the machine that you developed the DLL, you have installed a C++ compiler and that installed the runtime for you. On your target machine, where the code fails, you have not installed the compiler and so the runtime is not present.

这篇关于WindowsError: [Error 126] 加载带有 ctypes 的 DLL 时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆