Freezing a program that uses pywin32/win32api results in an executable that crashes with
Error: DLL load failed while importing win32api: The specified module could not be found.
The root cause seems to be that it cannot find the pywintypes38.dll library on freeze. The warnings are:
10812 WARNING: lib not found: pywintypes38.dll dependency of ...\venv\lib\site-packages\win32\win32evtlog.pyd
10835 WARNING: lib not found: pywintypes38.dll dependency of ...\venv\lib\site-packages\win32\win32api.pyd
pywintypes38.dll is located in ...\venv\Lib\site-packages\pywin32_system32
pyinstaller --version stable: 3.6pyinstaller --version devel: 4.0.dev0+g61925346Tried to add the DLL as a hidden import still didn't take.
I finally got it. Apparently hidden-imports are python imports (couldn't find an example in the official documentation) and the module that needs to be imported is pywintypes.
I have done some more digging and apparently this "import" is problematic in the first place. It is solved using pywintypes.py that does some resolving we might need to do or just run the that code.
So --hidden-import=pywintypes fixed it?
Yes!
Most helpful comment
Yes!