gpt4 book ai didi

python - Pybind11 : "ImportError: DLL not found" when trying to import *. Python解释器中的pyd

转载 作者:行者123 更新时间:2023-12-01 14:48:52 33 4
gpt4 key购买 nike

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

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

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 )并得到了一个错误,如下所示:

enter image description here

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

我如何制作 .pyd :
  • 创建空的 Visual Studio 项目(Win32;Python 也是 32 位安装)
  • 将项目设置更改为 .dll -配置和.pyd -文件扩展名
  • 为 OpenCV、LibRaw 和 Pybind11
  • 的头文件添加了包含路径
  • 为 OpenCV、LibRaw 和 Python3.8
  • 的链接器添加了路径和输入文件
  • 构建解决方案(无错误,无警告)
  • 尝试导入结果 .pyd在 python 解释器中

  • 我看过 this question ,其中 OP 存在不同 Python 的问题- .dlls由库加载,但在我的情况下,Dependency Walker 引用的库与我的路径变量中的库相同。

    最佳答案

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

    然而,事实并非如此,因为 ProcMon透露。现在,我复制了丢失的 .dll s 到包含 .pyd 的文件夹一切正常。

    关于python - Pybind11 : "ImportError: DLL not found" when trying to import *. Python解释器中的pyd,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59860465/

    33 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com