If you've already tried optimization techniques and still have a large 1GB executable, let's do some deeper diagnostics and advanced optimization:
Advanced Troubleshooting
-
Dependency Analysis
pyinstaller --debug=all your_script.py
This will generate a detailed log showing exactly what's being bundled.
-
Explicit Module Exclusion
Create a comprehensive exclusion list:
pyinstaller --onefile --windowed \
--exclude-module test \
--exclude-module unittest \
--exclude-module matplotlib \
--exclude-module scipy \
--exclude-module numpy \
--exclude-module PIL \
--exclude-module tkinter \
--exclude-module wx \
--exclude-module PyQt5.QtWebEngine \
--exclude-module PyQt5.QtMultimedia \
--exclude-module PyQt5.QtTest \
your_script.py
-
Minimal PyQt Approach
Instead of full PyQt5, consider:
- Use
PyQt5.QtWidgets only
- Explicitly import only required modules
- Avoid importing entire libraries
Specific Reduction Techniques
1. Minimal PyQt Import
from PyQt5.QtWidgets import (
QApplication, QMainWindow, QWidget,
QVBoxLayout, QLabel, QPushButton
)
from PyQt5.QtCore import Qt
2. Use --add-binary Carefully
pyinstaller --add-binary "path/to/specific/dll:." your_script.py
3. Create Custom .spec File
Generate and manually edit:
pyi-makespec --onefile --windowed your_script.py
Then edit the .spec file, removing unnecessary binaries.
Advanced Tools
-
Nuitka Compilation
pip install nuitka
python -m nuitka --follow-imports --standalone --onefile your_script.py
-
cx_Freeze Alternative
pip install cx_Freeze
python setup.py build
Diagnostic Steps
-
Check Included Libraries
pyinstaller --debug=imports your_script.py
-
Analyze Executable
Use tools like:
- Process Explorer
- Dependencies Walker
- Dependency Viewer
Potential High-Size Culprits
- Large data files
- Embedded images/resources
- Unnecessary Qt modules
- Scientific computing libraries
- Matplotlib
- NumPy
- Pandas
Recommended Workflow
- Minimal imports
- Use
--exclude-module
- Manually review
.spec file
- Consider alternative compilation methods
Sample Minimal .spec Configuration
a = Analysis(['your_script.py'],
pathex=['/path/to/your/project'],
binaries=[],
datas=[],
excludes=[
'matplotlib',
'scipy',
'numpy',
'PIL',
'PyQt5.QtWebEngine',
'PyQt5.QtMultimedia'
],
runtime_hooks=[],
...)
Last Resort Options
- Manually package only essential DLLs
- Use web-based alternatives
- Distribute as a lightweight installer
Would you like me to help you analyze your specific script to identify size bottlenecks?
If you're comfortable sharing a snippet of your code or the PyInstaller debug log, I can provide more targeted advice on reducing the executable size.