Pyinstaller ImportError : DLL load failed while importing win32gui

Viewed 2641

The program works fine including the win32gui calls but the executable gives this error

  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
2 Answers

Problem was hidden imports

So if someone has the same problem you need to add the missing module when building the executable as follows:

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

For my case the missing module was win32gui. After fixing it, it was another one: screenshot_every from d3dshot library

So basically you will face this problem if it was a sub import aka :

from d3dshot import screenshot_every

so screenshot_every is the hidden import ( you will need to do this to reduce the .exe size )

Win32gui isn't compatible with python-3.7 or above

python-3.7 was released in 2018 and the latest version of win32gui was released in August 2017.

Install pywin32. That gives you win32gui

$pip install pywin32
import win32api
Related