Skip to content

Compiling exe with PyInstaller results in missing parts #1385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Poikilos opened this issue Jul 16, 2024 · 1 comment
Open

Compiling exe with PyInstaller results in missing parts #1385

Poikilos opened this issue Jul 16, 2024 · 1 comment

Comments

@Poikilos
Copy link

Poikilos commented Jul 16, 2024

Environment

  • Python 3.12.2
  • zeroconf.__version__ '0.132.2'
  • Windows 11

Description

Launching an exe created by PyInstaller results in:

Traceback (most recent call last):
  File "main.py", line 35, in <module>
    from zeroconf import ServiceBrowser, ServiceListener, Zeroconf
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
  File "zeroconf\__init__.py", line 26, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
  File "zeroconf\_core.py", line 32, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
  File "zeroconf\_engine.py", line 38, in <module>
  File "src\\zeroconf\\_listener.py", line 1, in init zeroconf._listener
  File "src\\zeroconf\\_services\\info.py", line 1, in init zeroconf._services.info
ModuleNotFoundError: No module named 'zeroconf._utils.ipaddress'
[11808] Failed to execute script 'main' due to unhandled exception!
  • The exact same error happens if using import zeroconf.
  • For some reason, the only file in the zeroconf/_utils folder is time.cp312-win_amd64.pyd (notice there is no ipaddress module there)

Related issues

@Poikilos
Copy link
Author

Ok, it turns out PyInstaller didn't find parts of it. Workaround:

a = Analysis(
    ...
    hiddenimports=[
        'zeroconf._utils.ipaddress',  # and potentially others in .venv\Lib\site-packages\zeroconf\_utils, but that seems to pull in every pyd file
        'zeroconf._handlers.answers',  # and potentially others in .venv\Lib\site-packages\zeroconf\_handlers, but that seems to pull in every pyd file
        # and potentially others in _protocol or _services in .venv\Lib\site-packages\zeroconf\, but the above imports seem to pull in every pyd file from these
    ],
    ...
  • These imports allowed the following parts to work: from zeroconf import ServiceBrowser, ServiceListener, Zeroconf. However, other components may require more as noted in the comments above.

A full solution would be to add PyInstaller hooks to zeroconf (I may try to learn how...) if that is able to deal with the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant