Skip to content

Commit 59114d8

Browse files
committed
fix: Ensure telegram_selector module is included in PyInstaller builds
- Move telegram_selector import to top of widgets/__init__.py - Add explicit imports in main.py and app/gui/main.py - Create PyInstaller hook file for telegram_selector module - Add BUILD_INSTRUCTIONS.md with PyInstaller build guidance - Fixes 'No module named app.gui.widgets.telegram_selector' error in executables
1 parent 66a0aa2 commit 59114d8

5 files changed

Lines changed: 86 additions & 1 deletion

File tree

BUILD_INSTRUCTIONS.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Build Instructions for PyInstaller
2+
3+
## Including telegram_selector Module
4+
5+
The `telegram_selector` module must be explicitly included when building with PyInstaller.
6+
7+
### Option 1: Use the Hook File (Recommended)
8+
9+
The project includes a PyInstaller hook file at `hooks/hook-app.gui.widgets.telegram_selector.py`.
10+
11+
When building with PyInstaller, use the `--additional-hooks-dir` flag:
12+
13+
```bash
14+
pyinstaller --additional-hooks-dir=hooks main.py
15+
```
16+
17+
### Option 2: Use Hidden Imports
18+
19+
Alternatively, you can use the `--hidden-import` flag:
20+
21+
```bash
22+
pyinstaller --hidden-import=app.gui.widgets.telegram_selector main.py
23+
```
24+
25+
### Option 3: Create a Spec File
26+
27+
Create a `main.spec` file with hidden imports:
28+
29+
```python
30+
# -*- mode: python ; coding: utf-8 -*-
31+
32+
a = Analysis(
33+
['main.py'],
34+
pathex=[],
35+
binaries=[],
36+
datas=[],
37+
hiddenimports=['app.gui.widgets.telegram_selector'],
38+
hookspath=['hooks'],
39+
...
40+
)
41+
```
42+
43+
Then build with:
44+
```bash
45+
pyinstaller main.spec
46+
```
47+
48+
## Complete Build Command Example
49+
50+
```bash
51+
pyinstaller \
52+
--name=telegram-multi-account-sender \
53+
--onefile \
54+
--windowed \
55+
--icon=assets/icons/favicon.ico \
56+
--additional-hooks-dir=hooks \
57+
--hidden-import=app.gui.widgets.telegram_selector \
58+
--add-data "app/translations;app/translations" \
59+
--add-data "assets;assets" \
60+
main.py
61+
```
62+

app/gui/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
from ..services import get_settings, get_logger
1515
from ..services.translation import get_translation_manager, _
1616
from .theme import ThemeManager
17+
# Explicitly import telegram_selector to ensure PyInstaller includes it
18+
from .widgets.telegram_selector import TelegramSelectorDialog
1719
from .widgets import AccountWidget, CampaignWidget, LogWidget, RecipientWidget, SettingsWidget, DashboardWidget, PluginWidget
1820
from .widgets.about_widget import AboutWidget
1921

app/gui/widgets/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
Reusable GUI widgets for the application.
33
"""
44

5+
# Import telegram_selector first to ensure PyInstaller includes it
6+
from .telegram_selector import TelegramSelectorDialog
7+
58
from .account_widget import AccountWidget, AccountListWidget
69
from .campaign_widget import CampaignWidget, CampaignListWidget
710
from .template_widget import TemplateWidget, TemplateListWidget
@@ -10,7 +13,6 @@
1013
from .log_widget import LogWidget, LogViewer
1114
from .settings_widget import SettingsWidget
1215
from .dashboard_widget import DashboardWidget
13-
from .telegram_selector import TelegramSelectorDialog
1416
from .plugin_widget import PluginWidget, PluginListWidget
1517

1618
__all__ = [
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""
2+
PyInstaller hook for app.gui.widgets.telegram_selector module.
3+
4+
This ensures the telegram_selector module is included in PyInstaller builds.
5+
"""
6+
7+
from PyInstaller.utils.hooks import collect_all
8+
9+
# Collect all dependencies for the telegram_selector module
10+
datas, binaries, hiddenimports = collect_all('app.gui.widgets.telegram_selector')
11+
12+
# Explicitly add the module to hidden imports
13+
hiddenimports += [
14+
'app.gui.widgets.telegram_selector',
15+
'app.gui.widgets.telegram_selector.TelegramSelectorDialog',
16+
]
17+

main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
sys.path.insert(0, str(app_dir))
1414

1515
from app.services import initialize_database, get_settings, get_logger, initialize_plugins
16+
# Explicitly import telegram_selector early to ensure PyInstaller includes it
17+
from app.gui.widgets.telegram_selector import TelegramSelectorDialog
1618
from app.gui.main import MainWindow
1719

1820
# Import all models to ensure they are registered with SQLModel

0 commit comments

Comments
 (0)