pythonc++dllimporterrordependency-walker

Pybind11: "ImportError: DLL not found" when trying to import *.pyd in Python Interpreter


I built a .pyd in Visual Studio 2019 (Community) that provides a wrapper for some functionality that's only present in the LibRaw. The solution compiles successfully without any warnings or errors. The project uses LibRaw, OpenCV and pybind11 as well as Python.h and the corresponding .lib-file.

When i try to import the .pyd inside the Python Interpreter i get:

C:\Users\Tim.Hilt\source\repos\cr3_converter\Release>dir
 Datenträger in Laufwerk C: ist Acer
 Volumeseriennummer: EC36-E45E

 Verzeichnis von C:\Users\Tim.Hilt\source\repos\cr3_converter\Release

22.01.2020  11:28    <DIR>          .
22.01.2020  11:28    <DIR>          ..
22.01.2020  11:28               808 cr3_converter.exp
22.01.2020  11:28         3.068.361 cr3_converter.iobj
22.01.2020  11:28           785.552 cr3_converter.ipdb
22.01.2020  11:28             1.908 cr3_converter.lib
22.01.2020  11:28         4.190.208 cr3_converter.pdb
22.01.2020  11:28           953.856 cr3_converter.pyd
31.10.2019  16:22        26.408.085 IMG_0482_raw.CR3
               7 Datei(en),     35.408.778 Bytes
               2 Verzeichnis(se), 77.160.587.264 Bytes frei

C:\Users\Tim.Hilt\source\repos\cr3_converter\Release>python
Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 22:39:24) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cr3_converter
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: DLL load failed while importing cr3_converter: The specified module was not found.
>>> import cr3_converter.pyd
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: DLL load failed while importing cr3_converter: The specified module was not found.
>>>

The Paths to the needed .dlls (Python and OpenCV in this case; LibRaw was linked fully statically) are set in the system-path.

I ran Dependency-Walker, but could not find anything suspicious. Here is the corresponding Dependency Walker image. I also tried out another tool (Dependencies.exe, which is essentially a rewrite of Dependency Walker, but takes into account the API-MS-WIN-CORE-....dlls) and got an error, which looked like this:

enter image description here

When i hover over the missing .dll, i can see a api-ms-win... module could not be found on disk. I have searched and found the module and added its directory-path to the system-path. Now the module isn't highlighted red anymore, but the C:\WINDOWS\SysWOW64\WS2_32.dll (red highlight at top of screenshot) still shows to have missing imports. Could this be an issue?

How i've produced the .pyd:

I've seen this question, where the OP had the problem of different Python-.dlls being loaded by the library, but in my case the library referenced by Dependency Walker is the same as the one i have in my path-variable.


Solution

  • I quietly assumed, that Windows searches for .dlls in the same directories as the ones listed in the systems (/users) PATH-variable.

    However, that is not the case, as ProcMon revealed. For now, i copied the missing .dlls to the folder that contains the .pyd and everything works.