Pyinstaller ImportError:导入win32gui时DLL加载失败

时间:2020-04-09 21:12:57

标签: python dll pyinstaller pywin32 win32gui

该程序可以正常运行,包括win32gui调用,但可执行文件给出此错误

  File "Client.py", line 1, in <module>
ImportError: DLL load failed while importing win32gui: Le module spécifié est introuvable.
[4628] Failed to execute script Client```

I am running on : 
Win 10 
Python 3.8

1 个答案:

答案 0 :(得分:1)

问题是隐藏的进口

因此,如果有人遇到相同的问题,则在构建可执行文件时需要添加缺少的模块,如下所示:

pyinstaller pathToYourPythonFile/script.py --onefile --hidden-import theMissingModule

对于我来说,缺少的模块是 win32gui 。修复后,又是另一个问题: d3dshot 库中的 screenshot_every

因此,基本上,如果它是 sub import aka,您将面临这个问题:

from d3dshot import screenshot_every

所以screenshot_every是隐藏的导入(您需要执行此操作以减小 .exe 大小)