Hi guys,

May I ask some questions regarding using Pyinstaller to package a Python 
project using Transformers. Seems that Pyinstaller does not work with 
dynamic lazy import well, so I explicitly add them (transformers) to the 
hidden import. But it still did not work as expected. The following is the 
details.
My code has this 
from transformers import pipeline

The following is my .spec file:
from PyInstaller.utils.hooks import collect_all, collect_data_files

# Collect all necessary files from the 'transformers' package
transformers_datas = collect_data_files('transformers', 
include_py_files=True)
transformers_binaries, transformers_hiddenimports = 
collect_all('transformers')[1:]

a = Analysis(
['main.py'],
pathex=['.', './.venv/lib/python3.12/site-packages'],
binaries=transformers_binaries,
datas=transformers_datas,
hiddenimports=transformers_hiddenimports,
hookspath=[],
runtime_hooks=[],
excludes=[],
noarchive=False,
)

pyz = PYZ(a.pure)

exe = EXE(
pyz,
a.scripts,
[],
exclude_binaries=True,
name='some_app',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=False,
icon='resources/icon.icns',
)

coll = COLLECT(
exe,
a.binaries,
a.datas,
strip=False,
upx=True,
name='some_app',
)

app = BUNDLE(
coll,
name='some_app.app',
icon='resources/icon.icns',
bundle_identifier=None,
)

After building the package and running the executable, I got the following 
error.
Traceback (most recent call last):
  File "transformers/utils/import_utils.py", line 2073, in _get_module
  File "importlib/__init__.py", line 90, in import_module
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  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 450, in exec_module
  File "transformers/pipelines/__init__.py", line 27, 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 450, in exec_module
  File "transformers/models/__init__.py", line 341, in <module>
  File "transformers/utils/import_utils.py", line 2597, in 
define_import_structure
  File "transformers/utils/import_utils.py", line 2308, in 
create_import_structure_from_path
FileNotFoundError: [Errno 2] No such file or directory: 
'./dist/Sumnote/_internal/transformers/models/__init__.pyc'

The above exception was the direct cause of the following exception:
...
  File "transformers/utils/import_utils.py", line 2048, in __getattr__
    raise ModuleNotFoundError(
ModuleNotFoundError: Could not import module 'pipeline'. Are this object's 
requirements defined correctly?

Could somebody help me for this case?



-- 
You received this message because you are subscribed to the Google Groups 
"PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pyinstaller+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/pyinstaller/df762c33-47f9-4e92-8fd1-1cb073bcad31n%40googlegroups.com.

Reply via email to