如何在Python中“ImportError: DLL load failed while importing”中查找失败的DLL?

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

背景

是否有命令可以增强收到的错误消息,以便 python 显示它找不到哪个

.dll
文件?

错误:

python test_cv2.py
Traceback (most recent call last):
  File "test_cv2.py", line 1, in <module>
    import cv2
  File "E:\Anaconda3\envs\py38\lib\site-packages\cv2\__init__.py", line 5, in <module>
    from .cv2 import *
ImportError: DLL load failed while importing cv2: The specified module could not be found.

(py38) E:\somepath>

我想确定实际上没有找到哪个

.dll
文件。为此,我从
此存储库下载并运行 
DependenciesGui.exe。接下来,我喂了
DependenciesGui.exe
cv2.cp38-win_amd64.pyd
,这表明
api-ms-win-core-wow64-l1-1-1.dll
丢失了。

我目前没有办法验证

.dll
报告丢失的
dependenciesGUI.exe
文件也是 python 3.8 在 anaconda 环境中找不到的文件。

隐式验证 python 3.8 丢失的

.dll
文件与
dependenciesGUI.exe
报告丢失的相同文件是否相同的一种方法是下载所有丢失的
.dll
文件并将其粘贴到
../system32/
中。接下来检查错误消息是否消失/更改。然而,报告丢失的
.dll
文件之一是:
api-ms-win-core-wow64-l1-1-1.dll
,我还无法找到(在线)。另外,我尝试作弊将
api-ms-win-core-wow64-l1-1-0.dll
复制并重命名为
api-ms-win-core-wow64-l1-1-1.dll
但(幸运的是)这并不能让
dpendenciesGUI.exe
识别找到的
.dll
文件。

问题

如何使 python 的错误消息/回溯明确提及未找到哪个

.dll
文件(第一个
.dll
文件)?

注意

这不是为了解决安装

xy-problem
opencv

python debugging dll anaconda
2个回答
0
投票

简短回答:否。

虽然这可能不是完全不可能,但它需要在Python中绑定像

dependenciesGUI
这样的工具,以便能够在给定的上下文中调用它(即考虑到Python中dll的实际搜索路径并且已经加载动态库)。这将是大量的工作却收效甚微。确实,Windows上Python>=3.8的默认搜索路径应该与
dependenciesGUI
非常相似,因此丢失的dll应该是相同的。就我个人而言,我正在为 Python 开发预编译的二进制发行版,到目前为止
dependenciesGUI
足以识别 Python 导入时丢失的库。


0
投票

刚刚遇到同样的问题,可以使用

dlltracer
模块来跟踪 dll 加载。在这里查找文档https://pypi.org/project/dlltracer/

(需要管理员权限)

import dlltracer
import sys

with dlltracer.Trace(out=sys.stdout):
    import module_to_trace
© www.soinside.com 2019 - 2024. All rights reserved.