当程序出现类似于下面的错误时:

1
2
3
4
5
6
7
# python
>>> import nncase
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\a\nncase\nncase\install\python\nncase\__init__.py", line 34, in <module>
import _nncase
ImportError: DLL load failed while importing _nncase: The specified module could not be found.

这意味着系统中存在某个dll确实的情况,一种简单的排查手段是使用Dependency Walker来进行定位,github链接为:Dependency Walker github

Dependency Walker

可以直接使用wget下载:

1
2
wget https://github.com/lucasg/Dependencies/releases/download/v1.11.1/Dependencies_x64_Release.zip
unzip xxx.zip

命令行模式

进入对应的目录下,找到Dependencies.exe(命令行执行)

1
./Dependencies.exe -depth 2 -chain  _nncase.cp38-win_amd64.pyd 

log如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# ./../../../Dependencies.exe -depth 2 -chain  _nncase.cp38-win_amd64.pyd 
├ _nncase.cp38-win_amd64.pyd (ROOT) : _nncase.cp38-win_amd64.pyd
| ├ Nncase.Runtime.Native.dll (Environment) : D:\a\nncase\nncase\install\bin\Nncase.Runtime.Native.dll
| | ├ libomp140.x86_64.dll (WindowsFolder) : C:\Windows\system32\libomp140.x86_64.dll
| | ├ KERNEL32.dll (WellKnownDlls) : C:\Windows\system32\kernel32.dll
| | | ├ api-ms-win-core-rtlsupport-l1-1-0.dll (ApiSetSchema) : C:\Windows\system32\ntdll.dll
| | | ├ api-ms-win-core-rtlsupport-l1-2-2.dll (ApiSetSchema) : C:\Windows\system32\ntdll.dll
| | | ├ ntdll.dll (WellKnownDlls) : C:\Windows\system32\ntdll.dll
| | | ├ api-ms-win-core-appcompat-l1-1-1.dll (ApiSetSchema) : C:\Windows\system32\kernelbase.dll
| | | ├ ext-ms-win-oobe-query-l1-1-0.dll (NOT_FOUND) :
| | | ├ RPCRT4.dll (WellKnownDlls) : C:\Windows\system32\rpcrt4.dll
| | ├ ADVAPI32.dll (WellKnownDlls) : C:\Windows\system32\advapi32.dll
| ├ python38.dll (Environment) : C:\hostedtoolcache\windows\Python\3.8.10\x64\python38.dll
| | ├ VERSION.dll (WindowsFolder) : C:\Windows\system32\VERSION.dll
| | ├ api-ms-win-crt-filesystem-l1-1-0.dll (ApiSetSchema) : C:\Windows\system32\ucrtbase.dll
| ├ KERNEL32.dll (WellKnownDlls) : C:\Windows\system32\kernel32.dll

可以很容易发现ext-ms-win-oobe-query-l1-1-0.dll这个dll不存在,然后google对应的问题解决

目前该问题没有合适的解决方法,只是操作系统版本不匹配导致

gflags

该方法目前没有找到非常合适的使用案例,tmate中无法使用event viewer工具,无法查看系统日志
gflags.exe 的命令使用如下e

1
/c/Program\ Files\ \(x86\)/Windows\ Kits/10/Debuggers/x64/gflags.exe -i c:/hostedtoolcache/windows/Python/3.8.10/x64/python.exe +sls

GUI界面

如果要使用GUI,则执行DependenciesGUI.exe

Dumpbin

如何在tmate中使用dumpbin

首先需要激活vscmd环境,不能直接使用windows server中的命令行,否则无法找到dumpbin工具
$ cd /c/Program Files/Microsoft Visual Studio/2022/Enterprise/Common7/Tools
$ ./LaunchDevCmd.bat
之后就激活了vscmd命令行环境,vs相关的工具都可以使用

dumpbin使用

首先使用/DEPENDENTS 来查找当前库所依赖的dll,之后逐级查找
dumpbin /DEPENDENTS _nncase.cp38-win_amd64.pyd

1
2
3
4
5
6
7
8
9
10
11
12
Microsoft (R) COFF/PE Dumper Version 14.41.34120.0
Copyright (C) Microsoft Corporation. All rights reserved.

Dump of file _nncase.cp38-win_amd64.pyd

File Type: DLL

Image has the following dependencies:

Nncase.Runtime.Native.dll
python38.dll
KERNEL32.dll

dumpbin /DEPENDENTS D:\a\nncase\nncase\install\bin\Nncase.Runtime.Native.dll

1
2
3
4
5
6
7
8
9
Dump of file D:\a\nncase\nncase\install\bin\Nncase.Runtime.Native.dll

File Type: DLL

Image has the following dependencies:

libomp140.x86_64.dll
KERNEL32.dll
ADVAPI32.dll

dumpbin /DEPENDENTS C:\hostedtoolcache\windows\Python\3.8.10\x64\python38.dll

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Dump of file C:\hostedtoolcache\windows\Python\3.8.10\x64\python38.dll

File Type: DLL

Image has the following dependencies:

VERSION.dll
SHLWAPI.dll
WS2_32.dll
ADVAPI32.dll
KERNEL32.dll
VCRUNTIME140.dll
api-ms-win-crt-math-l1-1-0.dll
api-ms-win-crt-locale-l1-1-0.dll
api-ms-win-crt-string-l1-1-0.dll
api-ms-win-crt-runtime-l1-1-0.dll
api-ms-win-crt-stdio-l1-1-0.dll
api-ms-win-crt-convert-l1-1-0.dll
api-ms-win-crt-time-l1-1-0.dll
api-ms-win-crt-environment-l1-1-0.dll
api-ms-win-crt-process-l1-1-0.dll
api-ms-win-crt-heap-l1-1-0.dll
api-ms-win-crt-conio-l1-1-0.dll
api-ms-win-crt-filesystem-l1-1-0.dll

dumpbin /DEPENDENTS C:\Windows\System32\kernel32.dll

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
Dump of file C:\Windows\System32\kernel32.dll

File Type: DLL

Image has the following dependencies:

api-ms-win-core-rtlsupport-l1-1-0.dll
api-ms-win-core-rtlsupport-l1-2-2.dll
ntdll.dll
KERNELBASE.dll
api-ms-win-core-processthreads-l1-1-0.dll
api-ms-win-core-processthreads-l1-1-3.dll
api-ms-win-core-processthreads-l1-1-2.dll
api-ms-win-core-processthreads-l1-1-1.dll
api-ms-win-core-registry-l1-1-0.dll
api-ms-win-core-heap-l1-1-0.dll
api-ms-win-core-heap-l2-1-0.dll
api-ms-win-core-memory-l1-1-1.dll
api-ms-win-core-memory-l1-1-0.dll
api-ms-win-core-memory-l1-1-2.dll
api-ms-win-core-handle-l1-1-0.dll
api-ms-win-core-synch-l1-1-0.dll
api-ms-win-core-synch-l1-2-1.dll
api-ms-win-core-synch-l1-2-0.dll
api-ms-win-core-file-l1-1-0.dll
api-ms-win-core-file-l1-2-0.dll
api-ms-win-core-file-l1-2-2.dll
api-ms-win-core-file-l1-2-4.dll
api-ms-win-core-file-l1-2-1.dll
api-ms-win-core-delayload-l1-1-0.dll
api-ms-win-core-io-l1-1-0.dll
api-ms-win-core-io-l1-1-1.dll
api-ms-win-core-job-l1-1-0.dll
api-ms-win-core-threadpool-legacy-l1-1-0.dll
api-ms-win-core-threadpool-private-l1-1-0.dll
api-ms-win-core-largeinteger-l1-1-0.dll
api-ms-win-core-libraryloader-l1-2-3.dll
api-ms-win-core-libraryloader-l1-2-2.dll
api-ms-win-core-libraryloader-l1-2-0.dll
api-ms-win-core-libraryloader-l1-2-1.dll
api-ms-win-core-libraryloader-l2-1-0.dll
api-ms-win-core-namedpipe-l1-2-2.dll
api-ms-win-core-namedpipe-l1-1-0.dll
api-ms-win-core-namedpipe-l1-2-1.dll
api-ms-win-core-datetime-l1-1-1.dll
api-ms-win-core-datetime-l1-1-0.dll
api-ms-win-core-datetime-l1-1-2.dll
api-ms-win-core-sysinfo-l1-2-0.dll
api-ms-win-core-sysinfo-l1-2-1.dll
api-ms-win-core-sysinfo-l1-1-0.dll
api-ms-win-core-sysinfo-l1-2-3.dll
api-ms-win-core-timezone-l1-1-0.dll
api-ms-win-core-localization-l1-2-0.dll
api-ms-win-core-processsnapshot-l1-1-0.dll
api-ms-win-core-processenvironment-l1-1-0.dll
api-ms-win-core-processenvironment-l1-2-0.dll
api-ms-win-core-string-l1-1-0.dll
api-ms-win-core-debug-l1-1-0.dll
api-ms-win-core-debug-l1-1-1.dll
api-ms-win-core-errorhandling-l1-1-0.dll
api-ms-win-core-errorhandling-l1-1-3.dll
api-ms-win-core-fibers-l1-1-0.dll
api-ms-win-core-util-l1-1-0.dll
api-ms-win-core-profile-l1-1-0.dll
api-ms-win-security-base-l1-1-0.dll
api-ms-win-security-base-l1-2-0.dll
api-ms-win-security-appcontainer-l1-1-0.dll
api-ms-win-core-comm-l1-1-0.dll
api-ms-win-core-realtime-l1-1-0.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-3.dll
api-ms-win-core-systemtopology-l1-1-1.dll
api-ms-win-core-systemtopology-l1-1-0.dll
api-ms-win-core-processtopology-l1-1-0.dll
api-ms-win-core-namespace-l1-1-0.dll
api-ms-win-core-file-l2-1-2.dll
api-ms-win-core-file-l2-1-0.dll
api-ms-win-core-file-l2-1-1.dll
api-ms-win-core-file-l2-1-3.dll
api-ms-win-core-xstate-l2-1-0.dll
api-ms-win-core-xstate-l2-1-1.dll
api-ms-win-core-xstate-l2-1-2.dll
api-ms-win-core-localization-l2-1-0.dll
api-ms-win-core-normalization-l1-1-0.dll
api-ms-win-core-fibers-l2-1-0.dll
api-ms-win-core-fibers-l2-1-1.dll
api-ms-win-core-localization-private-l1-1-0.dll
api-ms-win-core-sidebyside-l1-1-0.dll
api-ms-win-core-appcompat-l1-1-0.dll
api-ms-win-core-windowserrorreporting-l1-1-1.dll
api-ms-win-core-windowserrorreporting-l1-1-2.dll
api-ms-win-core-windowserrorreporting-l1-1-0.dll
api-ms-win-core-windowserrorreporting-l1-1-3.dll
api-ms-win-core-console-l1-1-0.dll
api-ms-win-core-console-l1-2-0.dll
api-ms-win-core-console-l1-2-1.dll
api-ms-win-core-console-l2-1-0.dll
api-ms-win-core-console-l2-2-0.dll
api-ms-win-core-console-l3-2-0.dll
api-ms-win-core-psapi-l1-1-0.dll
api-ms-win-core-psapi-ansi-l1-1-0.dll
api-ms-win-eventing-provider-l1-1-0.dll
api-ms-win-core-apiquery-l1-1-0.dll
api-ms-win-core-delayload-l1-1-1.dll
api-ms-win-core-appcompat-l1-1-1.dll

Image has the following delay load dependencies:

ext-ms-win-oobe-query-l1-1-0.dll
RPCRT4.dll