Skip to content

Commit 89efdff

Browse files
committed
fix: Add PyInstaller spec file and improve telegram_selector inclusion
- Create main.spec file with explicit hidden imports - Improve hook file to use collect_submodules - Add try/except fallback in widgets __init__.py - Update BUILD_INSTRUCTIONS.md with spec file as recommended method - Ensures telegram_selector is always included in PyInstaller builds
1 parent 44fd2af commit 89efdff

3 files changed

Lines changed: 42 additions & 32 deletions

File tree

BUILD_INSTRUCTIONS.md

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,59 +4,60 @@
44

55
The `telegram_selector` module must be explicitly included when building with PyInstaller.
66

7-
### Option 1: Use the Hook File (Recommended)
7+
### Option 1: Use the Spec File (Recommended)
88

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:
9+
The project includes a `main.spec` file that explicitly includes all necessary modules.
1210

11+
Build with:
1312
```bash
14-
pyinstaller --additional-hooks-dir=hooks main.py
13+
pyinstaller main.spec
1514
```
1615

17-
### Option 2: Use Hidden Imports
16+
For Windows (console version), edit `main.spec` and change `console=False` to `console=True`.
1817

19-
Alternatively, you can use the `--hidden-import` flag:
18+
### Option 2: Use the Hook File
2019

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:
20+
The project includes a PyInstaller hook file at `hooks/hook-app.gui.widgets.telegram_selector.py`.
2821

29-
```python
30-
# -*- mode: python ; coding: utf-8 -*-
22+
When building with PyInstaller, use the `--additional-hooks-dir` flag:
3123

32-
a = Analysis(
33-
['main.py'],
34-
pathex=[],
35-
binaries=[],
36-
datas=[],
37-
hiddenimports=['app.gui.widgets.telegram_selector'],
38-
hookspath=['hooks'],
39-
...
40-
)
24+
```bash
25+
pyinstaller --onefile --noconsole --additional-hooks-dir=hooks --hidden-import=app.gui.widgets.telegram_selector main.py
4126
```
4227

43-
Then build with:
28+
### Option 3: Use Hidden Imports Only
29+
4430
```bash
45-
pyinstaller main.spec
31+
pyinstaller --onefile --noconsole --hidden-import=app.gui.widgets.telegram_selector main.py
4632
```
4733

48-
## Complete Build Command Example
34+
## Complete Build Command Example (Windows)
4935

5036
```bash
5137
pyinstaller \
5238
--name=telegram-multi-account-sender \
5339
--onefile \
54-
--windowed \
40+
--noconsole \
5541
--icon=assets/icons/favicon.ico \
5642
--additional-hooks-dir=hooks \
5743
--hidden-import=app.gui.widgets.telegram_selector \
44+
--hidden-import=PyQt5 \
45+
--hidden-import=PyQt5.QtCore \
46+
--hidden-import=PyQt5.QtGui \
47+
--hidden-import=PyQt5.QtWidgets \
5848
--add-data "app/translations;app/translations" \
5949
--add-data "assets;assets" \
6050
main.py
6151
```
6252

53+
## Troubleshooting
54+
55+
If you still get the "No module named 'app.gui.widgets.telegram_selector'" error:
56+
57+
1. **Use the spec file**: `pyinstaller main.spec` (most reliable)
58+
2. **Check the hooks directory**: Ensure `hooks/hook-app.gui.widgets.telegram_selector.py` exists
59+
3. **Verify the file exists**: Check that `app/gui/widgets/telegram_selector.py` exists
60+
4. **Clean build**: Delete `build/` and `dist/` directories, then rebuild
61+
5. **Check PyInstaller version**: Ensure you're using a recent version of PyInstaller
62+
63+

app/gui/widgets/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
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
5+
# Import telegram_selector first using absolute import to ensure PyInstaller includes it
6+
try:
7+
from app.gui.widgets.telegram_selector import TelegramSelectorDialog
8+
except ImportError:
9+
# Fallback for relative import if absolute fails
10+
from .telegram_selector import TelegramSelectorDialog
711

812
from .account_widget import AccountWidget, AccountListWidget
913
from .campaign_widget import CampaignWidget, CampaignListWidget

hooks/hook-app.gui.widgets.telegram_selector.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
This ensures the telegram_selector module is included in PyInstaller builds.
55
"""
66

7-
from PyInstaller.utils.hooks import collect_all
7+
from PyInstaller.utils.hooks import collect_all, collect_submodules
88

99
# Collect all dependencies for the telegram_selector module
1010
datas, binaries, hiddenimports = collect_all('app.gui.widgets.telegram_selector')
@@ -13,5 +13,10 @@
1313
hiddenimports += [
1414
'app.gui.widgets.telegram_selector',
1515
'app.gui.widgets.telegram_selector.TelegramSelectorDialog',
16+
'telegram_selector', # Also try without full path
1617
]
1718

19+
# Collect any submodules
20+
hiddenimports += collect_submodules('app.gui.widgets.telegram_selector')
21+
22+

0 commit comments

Comments
 (0)