Skip to content

Incompatibility with comtypes>=1.4.5 (ModuleNotFoundError: No module named 'comtypes.stream') #807

@Avasam

Description

@Avasam

Describe the bug
With comtypes 1.4.5 or above, my PyInstaller frozen application fails with "ModuleNotFoundError: No module named 'comtypes.stream'", supposing it fails to include comtypes.stream.

  • Which hook/library isn't working? comtypes
  • Does the error get raised while building or when running? running

To Reproduce
A minimal example file:

import comtypes.client
# A DLL that can be loaded on your machine, in my case, a lib was calling:
comtypes.client.GetModule("qedit.dll") 

PyInstaller command:

pyinstaller test.py --onefile

Error:

Traceback (most recent call last):
  File "test.py", line 3, in <module>
  File "comtypes\client\_generate.py", line 128, in GetModule
  File "comtypes\client\_generate.py", line 232, in generate
  File "comtypes\client\_generate.py", line 280, in _get_known_namespaces
  File "importlib\__init__.py", line 126, in import_module
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1140, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'comtypes.stream'

Expected behavior
No error. Probably through a hook letting pyinstaller know that importing comtypes.client._generate has a chance of requiring comtypes.stream.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Windows 10.0.19045 Build 19045
  • Python Version: 3.11.6
  • Version of pyinstaller-hooks-contrib: 2024.8
  • Version of PyInstaller 6.10.0

Additional context
Adding --hidden-import comtypes.stream works. But comtypes is a big/popular enough library I think it's valuable to work with it "as-is".

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions