【发布时间】:2020-05-08 15:46:19
【问题描述】:
我在 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。我还尝试了另一个工具(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的:
- 创建了空的 Visual Studio 项目(Win32;Python 也是 32 位安装)
- 将项目设置更改为
.dll-configuration 和.pyd-fileextension - 为 OpenCV、LibRaw 和 Pybind11 的头文件添加了包含路径
- 为 OpenCV、LibRaw 和 Python3.8 的链接器添加了路径和输入文件
- 构建解决方案(无错误,无警告)
- 试图在python解释器中导入生成的
.pyd
我见过this question,其中 OP 遇到了库加载不同 Python-.dlls 的问题,但在我的情况下,Dependency Walker 引用的库与我的库相同路径变量。
【问题讨论】:
标签: python c++ dll importerror dependency-walker