简体   繁体   English

WindowsError:[错误126]加载带有ctypes的DLL时

[英]WindowsError: [Error 126] when loading a DLL with ctypes

This works fine on Windows 7 with Python 2.7: 这在使用Python 2.7的Windows 7上运行良好:

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

The library prov_means.DLL is in my working directory. 库prov_means.DLL在我的工作目录中。 It exports a simple, stand-alone C function provmeans() with no dependencies. 它导出一个简单的,独立的C函数provmeans(),没有依赖。

When I try the same thing on Windows XP and Python 2.7 I get 当我在Windows XP和Python 2.7上尝试相同的操作时,我得到了

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

I have tried copying the DLL to Windows\\System32 and also entering the full path name 我尝试将DLL复制到Windows \\ System32并输入完整路径名

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

with and without the ".DLL" extension. 有和没有“.DLL”扩展名。 Nothing works. 什么都行不通。

Error 126 is what you get when a dependent DLL can not be found. 错误126是无法找到从属DLL时获得的错误。 There are two obvious causes for this: 这有两个明显的原因:

  1. Your DLL is not being located. 您的DLL未找到。
  2. Your DLL depends on other DLLs that cannot be found. 您的DLL依赖于无法找到的其他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. 我怀疑选项1是问题,但无论如何我认为我可能会使用该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. 因此,留下选项2,最常见的原因是您的目标机器没有安装C ++运行时。 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. 在目标计算机上安装C ++运行时,或在构建DLL时使用静态链接/MT ,这样就不需要重新分发运行时。

Probably, on the machine that you developed the DLL, you have installed a C++ compiler and that installed the runtime for you. 也许,在您开发DLL的机器上,您已经安装了C ++编译器并为您安装了运行时。 On your target machine, where the code fails, you have not installed the compiler and so the runtime is not present. 在目标机器上,代码失败,您尚未安装编译器,因此运行时不存在。

Which compiler did you use to build the library? 您使用哪个编译器来构建库? Maybe some required libraries are missing? 也许缺少一些必需的库? You can check what dependencies the library has with Dependency Walker (http://www.dependencywalker.com/)? 您可以使用Dependency Walker(http://www.dependencywalker.com/)查看库具有哪些依赖项?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM