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

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

我在 Visual Studio 2019(社区)中构建了一个 .pyd,它为仅存在于 LibRaw 中的某些功能提供了包装器。该解决方案编译成功,没有任何警告或错误。该项目使用 LibRaw、OpenCV 和 pybind11 以及 Python.h 和相应的 .lib-file.

当我尝试在 Python 解释器中导入 .pyd 时,我得到:

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.
>>>

所需 .dlls 的路径(Python 和 OpenCV 在这种情况下;LibRaw 是完全静态链接的)在系统路径中设置。

我运行Dependency-Walker,但找不到任何可疑的东西。 Here is the corresponding Dependency Walker image. I also tried out another tool (Dependencies.exe,本质上是对 Dependency Walker 的重写,但考虑到了 API-MS-WIN-CORE-....dlls) 并得到了一个错误,看起来像这样:

当我将鼠标悬停在丢失的 .dll 上时,我可以看到一个 api-ms-win... module could not be found on disk。我搜索并找到了模块并将其目录路径添加到系统路径。现在该模块不再以红色突出显示,但 C:\WINDOWS\SysWOW64\WS2_32.dll(屏幕截图顶部的红色突出显示)仍然显示缺少导入。这可能是个问题吗?

我是如何制作 .pyd:

我见过 this question,其中 OP 存在不同的 Python-.dlls 被库加载的问题,但在我的例子中是 Dependency Walker 引用的库与我的路径变量中的相同。

我悄悄假设,Windows 在与系统 (/users) PATH-变量中列出的目录相同的目录中搜索 .dlls。

然而,正如ProcMon所揭示的那样,情况并非如此。现在,我将丢失的 .dll 复制到包含 .pyd 的文件夹中,一切正常。