13

This works fine on Windows 7 with Python 2.7:

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

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

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 

I have tried copying the DLL to Windows\System32 and also entering the full path name

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

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

2 Answers 2

23

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

  1. Your DLL is not being located.
  2. Your DLL depends on other DLLs that cannot be found.

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.

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.

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.

Sign up to request clarification or add additional context in comments.

9 Comments

Thanks David. That sounded very plausible as I compiled on the Windows 7 machine with Visual Studio 2010 Express, which is not on the target machine. I installed the C++ runtime on the target machine as suggested and restarted. Same error unfortunately.
You could use Dependency Walker in profile mode to check this. But I'd consider rebuilding the DLL with /MT just to double check that it is not that dependency that is causing the problem.
Right, just rebuilt with /MT and it now runs on the target. Many thanks!
I think that means that you could solve the problem by installing the re-dist, but for a simple DLL then /MT is the easiest option. It lets your DLL stand alone.
This has been really helpful to me. Just googling it brought me to this post and am glad I found the solution so quickly with your help.
|
0

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/)?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.