0

When I tried to load a dll by python3 on Windows Server 2019 standard (Desktop Experience). I got "self._handle = _dlopen(self._name, mode) OSError: [WinError 126]

The specified module could not be found". The same dll works fine on Windows 10. Microsoft Visual C++ redistributable and .NET Framework have been installed. What else can I do to make it work?

sguan77
  • 1
  • 2
  • 1
    Use [Process Monitor](https://learn.microsoft.com/en-us/sysinternals/downloads/procmon) to see from where Python is _attempting_ to load the file. You can filter by `Process Name` `equals` `python.exe` and `Path` `contains` `dll` for example. This may point you in the right direction as to why it's not found there. – CherryDT Apr 15 '20 at 15:49
  • You may also get this error if the DLL itself is found but one of its dependencies is not. Those dependencies would also show up in your Process Monitor result, though. – CherryDT Apr 15 '20 at 15:51
  • 1
    @CherryDT, the first comment is good advice, including for the case of dependent DLLs -- except the executable will be named "python.exe", not "python3.exe". Dependency Walker, not so much. It's too outdated. – Eryk Sun Apr 15 '20 at 15:52
  • Thank you, edited the process name. I still do use dependency walker for these things now and then, though. But you are right - removed it. – CherryDT Apr 15 '20 at 15:52
  • An alternative way to find issues with dependencies is enabling [loader snaps](https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/show-loader-snaps) and using a [debugger](https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/debugger-download-tools), but this is a bit more advanced. See [this article](http://web.archive.org/web/20160119182545/http://blogs.msdn.com/b/junfeng/archive/2006/11/20/debugging-loadlibrary-failures.aspx) and [this SO question](https://stackoverflow.com/questions/16700810/). – CherryDT Apr 15 '20 at 15:56
  • Thank you all for the advice. Let me check dependencies. But wonder what are the difference between Win10 and Win Server. – sguan77 Apr 15 '20 at 16:11
  • It seems that LoadLibraryEx.DLL is missing from the python installation. Let me try to install python again. Thank you, especially @CherryDT. – sguan77 Apr 15 '20 at 16:26
  • That sounds weird to me, `LoadLibraryEx` is the Windows API function to load a DLL, and it resides in `kernel32.dll` (which surely exists, otherwise you couldn't even boot Windows). I don't think Python has a `LoadLibraryEx.DLL` file. – CherryDT Apr 15 '20 at 16:39
  • @CherryDT, I reinstalled python. It still has the same problem. I can't find LoadLibraryEx anywhere - maybe like you said it is in kernel32.dll. Now I got lost again. Thanks. – sguan77 Apr 15 '20 at 17:43
  • In my win10 system, the dll is working. i can't find "LoadLibraryEx" in the Process Monitor. – sguan77 Apr 15 '20 at 18:03
  • Could it also be the problem, I am using Windows Server 2019 Standard Evaluation OS? – sguan77 Apr 15 '20 at 18:14
  • There is no `LoadLibraryEx` DLL. It's a Windows API function, which is publicly exported by kernel32.dll and implemented in kernelbase.dll, and in turn that's implemented by NT's private (i.e. not part of the documented, public API) loader function `LdrLoadDll` in ntdll.dll. ctypes calls `LoadLibraryExW` when instantiating `CDLL`, `WinDLL`, or `OleDLL`. ctypes wrappers have no need to directly call `LoadLibraryExW`. – Eryk Sun Apr 15 '20 at 19:12
  • Can you please show me where you found the information you said? In process monitor, you should track what DLL files are accessed, especially what DLL files are attempted to be accessed and not found. Can you share a screenshot? – CherryDT Apr 15 '20 at 20:27
  • @CherryDT, OK give me a few minutes to get it. Thanks. – sguan77 Apr 15 '20 at 20:30

0 Answers0