pyinstaller/pyinstaller-hooks-contrib

ImportError: cannot import name '_pylon' from 'pypylon' after pyinstaller 6.3.0

cooper-li-crown-public opened this issue · 2 comments

Describe the bug

  • Which hook/library isn't working? hook-pypylon.py
  • Does the error get raised while building or when running? It is a running error

To Reproduce

A minimal example file:

from pypylon import pylon

# do nothing

PyInstaller command:

pyinstaller test.py

Error:

Traceback (most recent call last):
  File "test.py", line 1, in <module>
    from pypylon import pylon
  File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
  File "pypylon/pylon.py", line 40, in <module>
ImportError: cannot import name '_pylon' from 'pypylon' (/home/test/dist/test/_internal/pypylon/__init__.pyc)
[518161] Failed to execute script 'test' due to unhandled exception!

Expected behavior
The binary should import pylon library without error.

Desktop (please complete the following information):

  • OS: Ubuntu
  • Python Version: python 3.10.12
  • Version of pyinstaller-hooks-contrib: 2023.12
  • Version of PyInstaller 6.3.0

Additional context
pypylon version: 3.0.1

Possible reason and solution

_pylon.cpython-xxx.so and _genicam.cpython-xxx.so are missing in pypylon directory, manually copy them from _internal/ to _internal/pypylon solved it.

rokm commented

This part of the hook is incompatible with PyInstaller 6.x:

# Exclude the C++-extensions from automatic search, add them manually as data files
# their dependencies were already handled with collect_dynamic_libs
excludedimports = ['pypylon._pylon', 'pypylon._genicam']
for filename, module in collect_data_files('pypylon', include_py_files=True):
if (os.path.basename(filename).startswith('_pylon.')
or os.path.basename(filename).startswith('_genicam.')):
datas += [(filename, module)]

Because collect_data_files(..., include_py_files=True) does not include binary extensions anymore.

Does removing this part from your local copy of the hook fix the problem? (And does your pypylon-based frozen application work correctly?)

The pypylon-based application works well in other cases. It turns out removing that part or completely disable pypylon hook solves the problem. Alternatively, delete excludedimports = ['pypylon._pylon', 'pypylon._genicam'], which prevents copying these two .so files.