Setuptools: can not include pywin32

Pursuing my journey with setuptools, it seems one can’t make a binary for windows with pywin32 modules.

pywin32 wheel is correctly downloaded but the modules are not detected :

There are some missing modules: [ ... 'win32clipboard', 'win32com.gen_py', '', 'win32con', 'win32pdh', 'win32wnet', ... ]

I tried explicitly referencing win32xxx with 'include_modules, but I only get more errors :

Unknown module: win32clipboard
Unknown module: win32con

The only way to include pywin32 is to open the wheel, copy the dlls under pywin32_system32 the pyd under win32 and the .py files under win32/lib

Use this chunk of code as a guide, you can try setting up the package_data_dirs option of build_apps to get the dlls and pyd files copied over.

For the missing Python files, these should have been frozen with the rest of your app, but they likely had “hidden imports.” These are imports that are not obvious and Panda’s freeze tool cannot track their usage. Typically these are handled by explicitly adding them to include_modules. Have you tried wildcarding some modules? For example, you can try adding win32.*.* to include_modules to include win32 and all of its submodules.

Thank you, copying the dll and pyd worked with the following line:

        'package_data_dirs': {'win32': [('pywin32_system32/*', '', {}),
                                        ('win32/*.pyd', '', {})]},

However there is still the problem of The problem seems there is no top level module in pywin32, but rather a collection of modules. win32con is not imported as submodule like import win32.lib.win32con but directly as import win32con. Also, win32con is imported explicitly in my code, so it’s not a hidden import. So I think the freeze tool can not make the link between the import in my code and the hidden under win32/lib/

It tried include module with all the variation I could think of but to no avail.

        'include_modules': {'*': ['pywin32.*', 'pywin32.*.*', 'win32.*', 'win32.*.*']},

another problem is win32com.gen_py and it’s generated com objects, which freeze tool doesn’t support
maybe a way for implementing hooks should be provided like pyInstaller has?