Pyinstaller: ImportError: DLL load failed while importing win32api: The specified module could not be found.

Created on 18 Apr 2020  路  3Comments  路  Source: pyinstaller/pyinstaller

Description of the issue

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

Context information (for bug reports)

  • Output of pyinstaller --version stable: 3.6
  • Output of pyinstaller --version devel: 4.0.dev0+g61925346
  • Version of Python: e.g. 3.8
  • Platform: Windows 10 English
  • Did not try another platform as the issue is with a Windows specific library

Tried to add the DLL as a hidden import still didn't take.

Most helpful comment

Yes!

All 3 comments

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!

Was this page helpful?
0 / 5 - 0 ratings