Windowserror: [Error 126] the Specified Module Could Not Be Found

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

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 :) )

OSError: [WinError 126] module could not be found

Ok finally solved!

I got to know that such error could be thrown when the file dependencies are not satisfied or not found. So to check the dependencies you go first to Visual Studio Prompt and then navigate to the folder where libmxnet.dll exists and run the following command

dumpbin /dependents libmxnet.dll

and it will show you a list of required files.

What was missing in my case are some of nVidia GPU Computing Toolkit files Cuda 9.0 as libmxnet.dll asks for them and I was having toolkit version 10.0 instead!

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

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.

Keras Error OSError: [WinError 126] The specified module could not be found

It will work for me

Uninstall the Tensorflow and Keras and install them again, the answer is in the below link

See stackoverflow.com/questions/53328808/… – you have a mixed-up constellation of Tensorflow and Keras packages



Related Topics



Leave a reply



Submit