Doc de PyInstaller : https://www.pyinstaller.org/
Didacticiel : Executable GUI with Python. using Tkinter and Pyinstaller
Activer (ou créer) un environnement virtuel :
c:\monprojet> venv\scripts\activate
Installer PyInstaller :
(venv) c:\monprojet> pip install pyinstaller
Sous Python 3.10 impossible d'installer pyinstaller 5.6, j'ai donc forcé l'installation de pyinstaller 5.5 :
(venv) c:\monprojet> pip install pyinstaller==5.5
Méthode 1 : création d'un dossier avec l'exécutable et les dépendances
(venv) c:\monprojet> pyinstaller --noconfirm --onedir --windowed test.py
Méthode 2 : création d'un unique exécutable contenant tout
(venv) c:\monprojet> pyinstaller --noconfirm --onefile --windowed test.py
Générations suivantes :
La première génération écrit un dossier test.spec qui peut être édité afin de modifier les options de génération.
Après modification, la commande de régénération se résume à :
(venv) c:\monprojet> pyinstaller test.spec
Application utilisant CustomTKinter :
Voir https://github.com/TomSchimansky/CustomTkinter/wiki/Packaging#windows-pyinstaller-auto-py-to-exe
(venv) c:\monprojet> pyinstaller --noconfirm --onefile --windowed --add-data "./venv/lib/site-packages/customtkinter;customtkinter/" test.py
# -*- mode: python ; coding: utf-8 -*- a = Analysis( ['leuze.py'], # Nom du script principal pathex=[], binaries=[], datas=[], hiddenimports=[], hookspath=[], hooksconfig={}, runtime_hooks=[], excludes=[], noarchive=False, ) pyz = PYZ(a.pure) exe = EXE( pyz, a.scripts, [], exclude_binaries=True, name='wxLeuze', # Nom de l'exécutable : wxLeuze.exe debug=False, bootloader_ignore_signals=False, strip=False, upx=True, console=False, disable_windowed_traceback=False, argv_emulation=False, target_arch=None, codesign_identity=None, entitlements_file=None, ) coll = COLLECT( exe, a.binaries, a.datas, strip=False, upx=True, upx_exclude=[], name='wxLeuze', # Nom du sous-dossier : \dist\wxLeuze\ )