WindowsError: [Error 126] The specified module could not be found
Solution 1:
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.
Solution 2:
When I see things like this - it is usually because there are backslashes in the path which get converted.
For example - the following will fail - because \t in the string is converted to TAB character.
>>> import ctypes
>>> ctypes.windll.LoadLibrary("c:\tools\depends\depends.dll")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\tools\python271\lib\ctypes\__init__.py", line 431, in LoadLibrary
return self._dlltype(name)
File "c:\tools\python271\lib\ctypes\__init__.py", line 353, in __init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found
There are 3 solutions (if that is the problem)
a) Use double slashes...
>>> import ctypes
>>> ctypes.windll.LoadLibrary("c:\\tools\\depends\\depends.dll")
b) use forward slashes
>>> import ctypes
>>> ctypes.windll.LoadLibrary("c:/tools/depends/depends.dll")
c) use RAW strings (prefacing the string with r
>>> import ctypes
>>> ctypes.windll.LoadLibrary(r"c:\tools\depends\depends.dll")
While this third one works - I have gotten the impression from time to time that it is not considered 'correct' because RAW strings were meant for regular expressions. I have been using it for paths on Windows in Python for years without problem :) )