python-zeroconf / python-zeroconf

A pure python implementation of multicast DNS service discovery
GNU Lesser General Public License v2.1
621 stars 224 forks source link

Issue compiling into exe with pyinstaller #1363

Open SamF111 opened 8 months ago

SamF111 commented 8 months ago

Hi, I am attempting to convert my script into an exe and zeroconf is causing issues.

pyinstaller v6.4.0 zeroconf v0.131.0 Python 3.12.2

import zeroconf ^^^^^^^^^^^^^^^ File "<frozen importlib._bootstrap>", line 1360, in _find_and_load File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 935, in _load_unlocked File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module File "zeroconf\__init__.py", line 26, in <module> File "<frozen importlib._bootstrap>", line 1360, in _find_and_load File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 935, in _load_unlocked File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module File "zeroconf\_core.py", line 32, in <module> File "<frozen importlib._bootstrap>", line 1360, in _find_and_load File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 935, in _load_unlocked 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 KeyError: '__reduce_cython__'

This appears to be an issue with how the cython in the project was compiled: https://github.com/cython/cython/issues/1953#issuecomment-398128940

mistrey commented 8 months ago

I have a similar problem. I can create the EXE with Pyinstaller but get an error during runtime.

pyinstaller v6.4.0 zeroconf v0.131.0 Python 3.9.2

Runtime error:

C:\Program Files\SARAD\RegServer-Service>.\regserver-service.exe install
<frozen importlib._bootstrap>:228: RuntimeWarning: zeroconf._dns.DNSRecord size changed, may indicate binary incompatibility. Expected 64 from C header, got 72 from PyObject
<frozen importlib._bootstrap>:228: RuntimeWarning: zeroconf._dns.DNSAddress size changed, may indicate binary incompatibility. Expected 88 from C header, got 96 from PyObject
<frozen importlib._bootstrap>:228: RuntimeWarning: zeroconf._dns.DNSHinfo size changed, may indicate binary incompatibility. Expected 88 from C header, got 96 from PyObject
<frozen importlib._bootstrap>:228: RuntimeWarning: zeroconf._dns.DNSPointer size changed, may indicate binary incompatibility. Expected 88 from C header, got 96 from PyObject
<frozen importlib._bootstrap>:228: RuntimeWarning: zeroconf._dns.DNSText size changed, may indicate binary incompatibility. Expected 80 from C header, got 88 from PyObject
<frozen importlib._bootstrap>:228: RuntimeWarning: zeroconf._dns.DNSService size changed, may indicate binary incompatibility. Expected 96 from C header, got 104 from PyObject
<frozen importlib._bootstrap>:228: RuntimeWarning: zeroconf._dns.DNSNsec size changed, may indicate binary incompatibility. Expected 88 from C header, got 96 from PyObject
Traceback (most recent call last):
  File "regserver-service.py", line 19, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
  File "registrationserver\main.py", line 27, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
  File "registrationserver\config.py", line 19, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
  File "zeroconf\__init__.py", line 26, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
  File "zeroconf\_core.py", line 32, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  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\\_handlers\\answers.py", line 1, in init zeroconf._handlers.answers
TypeError: C function zeroconf._utils.time.current_time_millis has wrong signature (expected PyObject *(int __pyx_skip_dispatch), got double (int __pyx_skip_dispatch))
[11180] Failed to execute script 'regserver-service' due to unhandled exception!

When using zeroconf v0.118.0 everything is fine.

mistrey commented 8 hours ago

https://github.com/python-zeroconf/python-zeroconf/issues/1385#issuecomment-2234042523 solved the problem for me.