问题描述
在Windows 7上使用Python 2.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:\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
我尝试过将DLL复制到Windows \System32并输入完整路径名称
I have tried copying the DLL to Windows\System32 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:
- 您的DLL未找到。
- 您的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 ++运行时,或使用静态链接,,构建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:加载ctypes DLL时出错[126]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!