So I'm working on an AI project using huggingface library, and I need to convert it into an exe file. I'm using PyQt5 for the interface, and transformers and datasets library from huggingface. I tried using PyInstaller to convert it into an exe file, it does finish building the exe files of the project, but it gives me this error when I run the exe file:
Traceback (most recent call last):
File "transformers\utils\versions.py", line 105, in require_version
File "importlib\metadata.py", line 530, in version
File "importlib\metadata.py", line 503, in distribution
File "importlib\metadata.py", line 177, in from_name
importlib.metadata.PackageNotFoundError: tqdm
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "App.py", line 5, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
File "transformers\__init__.py", line 43, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
File "transformers\dependency_versions_check.py", line 41, in <module>
File "transformers\utils\versions.py", line 120, in require_version_core
File "transformers\utils\versions.py", line 107, in require_version
importlib.metadata.PackageNotFoundError: The 'tqdm>=4.27' distribution was not found and is required by this application.
Try: pip install transformers -U or pip install -e '.[dev]' if you're working with git master
[736] Failed to execute script 'App' due to unhandled exception!
[process exited with code 1]
Line 5 on my code was a line of code for importing the transformers library.
...
4| from PyQt5.QtCore import QThread, QObject, pyqtSignal
5| from transformers import AutoTokenizer, AutoModelForQuestionAnswering, pipeline
...
...
And this is my .spec file:
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['App.py'],
pathex=[],
binaries=[],
datas=[
('./resources/images/logo.png', '.'),
('./resources/model/config.json', '.'),
('./resources/model/pytorch_model.bin', '.'),
('./resources/model/special_tokens_map.json', '.'),
('./resources/model/tokenizer.json', '.'),
('./resources/model/tokenizer_config.json', '.'),
('./resources/model/vocab.txt', '.')
],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
[],
exclude_binaries=True,
name='App',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True,
disable_windowed_traceback=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None , icon='logo.ico')
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='App')
I would really appreciate any help given, thanks :D
First, pip install tqdm
if you haven't already. Second, specify the path to your Lib/site-packages
. You can do this by either:
pathex
in your .spec
file
(.venv
for a virtual environment at some folder .venv
in your local directory, or the absolute path to your global Python install Lib/site-packages
if you're not using a virtual environment):pathex=['.venv/Lib/site-packages']
Lib/site-packages
from the command-line:pyinstaller --paths '.venv/Lib/site-packages' my_program.py
From the pyinstaller docs
pathex: a list of paths to search for imports (like using PYTHONPATH), including paths given by the --paths option.
Some Python scripts import modules in ways that PyInstaller cannot detect: for example, by using the __import__()
function with variable data, using importlib.import_module()
, or manipulating the sys.path
value at run time.