Python:导入错误:DLL 加载失败:pybind11 c++ 扩展

问题描述 投票:0回答:1

我正在努力刷新 Windows 的 pyEDM (https://github.com/SugiharaLab/pyEDM) 包。该包使用 pybind11 来包装 cppEDM(C++ 计算引擎),它直接从 C++ 代码调用 LAPACK。在 Nix 系统上,没问题。在 win 中,我使用 mingw 构建链接到二进制 libopenblas.lib 的 Py 扩展,该扩展在过去一直有效。这是基于 Azure DevOps 构建的,因为我在 Linux 中工作。

使用最新的 libopenblas.lib 构建成功。但是,在加载时我看到:

Import Error: DLL load failed while importing pyBindEDM: The specified module could not be found.

我看到轮子里有一个 pyBindEDM.cp39-win_amd64.pyd 文件,我理解它是扩展名的“dll”(Windows 对我来说是陌生的土地。)pyBindEDM 是通过 pybind11 导出的模块的名称,可见:

PYBIND11_MODULE( pyBindEDM, pyMod ) {
    pyMod.doc() = "Python bindings to cppEDM via pybind11.";
    ...
}

尝试在 Windows 10 计算机上使用 Dependency Walker 检查 .pyd 加载依赖关系,程序只是无休止地旋转而没有反馈。

一种方法如何解决 pybind11 包装的 C++ 扩展的导入错误?


更新:如果编辑原始帖子是不礼貌的行为,我深表歉意,我没有看到添加扩展名的选项。

重新定义问题:

如上所述,C++ 库 libEDM.a API 的 pybind11 包装器用于创建 pyEDM 包。 libEDM.a 直接调用 LAPACK

dgelss

之前,我使用 mingw 链接静态 openblas.a 来构建 .pyd。运行时不需要 .dll。现在,如果这是使用最新的 libopenblas.a 完成的,链接器会抱怨:

C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:\a\1\s\cppEDM/lib\openblas.lib(memory.obj):(.text+0x44a): undefined reference to `__imp__cprintf'

我一直没能解决这个问题。静态链接是首选方法。

第二种方法是针对 .dll (libopenblas.lib) 进行构建,这样就完成了。但是,当在Python中加载pyEDM包时:

Import Error: DLL load failed while importing pyEDMBind: The specified module could not be found.

使用依赖项应用程序(谢谢 Mašek),并且,如果我将 libopenblas.dll 放在 PATH 中,则未解析的 .pyd 依赖项是 python39.dll。

我不想尝试将 .dll 与包捆绑在一起,并解释为什么找不到 python39.dll,但无论如何,都无法提供可加载和运行的成功构建。

非常感谢任何和所有的指示。如果我有违反规范的地方,请原谅我缺乏岗位礼仪。

python dllimport pybind11
1个回答
0
投票

尽管问题尚未解决,因为 python 扩展在 Windows 上仍然失败,但有两个步骤至少可以部分解决所提出的问题。


问题 1:一种方法如何解决 pybind11 包装的 C++ 扩展的导入错误?

在 Windows 10 上,依赖项应用程序提供了答案:https://github.com/lucasg/Dependency

谢谢马塞克。


问题 2:将二进制 libopenblas.a 与 pybind11 C++ 扩展链接会产生:

C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:\a\1\s\cppEDM/lib\openblas.lib(memory.obj):(.text+0x44a): undefined reference to `__imp__cprintf'

似乎发布在 https://sourceforge.net/projects/openblas/ 上的二进制文件 libopenblas.a 是用 mingw 9.3 构建的,如果扩展是用 mingw 9.5 构建的,则未解析的引用将被解析。

© www.soinside.com 2019 - 2024. All rights reserved.