WindowsError: [Error 126] The specified module could not be found

MA1 picture MA1 · Dec 21, 2009 · Viewed 107.3k times · Source

I am loading a dll in python using following code:

if os.path.exists(dll_path):
     my_dll = ctypes.cdll.LoadLibrary(dll_path)

But I am continuously getting the following error

WindowsError: [Error 126] The specified module could not be found

dll is present at the specified path, but I didn't understand why I'm getting the error.

Answer

Doo Dah picture Doo Dah · Aug 25, 2014

Note that even if the DLL is in your path. If that DLL relies on other DLLs that are NOT in your path, you can get the same error. Windows could not find a dependency in this case. Windows is not real good at telling you what it could not find, only that it did not find something. It is up to you to figure that out. The Windows dll search path can be found here: http://msdn.microsoft.com/en-us/library/7d83bc18.aspx

In my case, being sure all needed dlls were in the same directory and doing a os.chdir() to that directory solved the problem.