#!/bin/bash # ============================================================ # build_lea_exe.sh — Cree un executable Windows autonome via PyInstaller # # IMPORTANT : Ce script doit tourner SUR WINDOWS (ou dans Wine/WSL # avec acces a un Python Windows). PyInstaller ne peut pas produire # un .exe Windows depuis Linux natif. # # Procedure recommandee : # 1. Sur le PC Windows (192.168.1.11 ou autre) : # - Installer Python 3.12 (https://python.org) # - pip install pyinstaller # 2. Copier ce script et le dossier agent_v0/ sur le PC Windows # 3. Executer depuis PowerShell/cmd : # python -m PyInstaller --onefile --windowed ^ # --name "Lea" ^ # --add-data "agent_v1;agent_v1" ^ # --add-data "lea_ui;lea_ui" ^ # --add-data "config.txt;." ^ # --hidden-import "pynput.keyboard._win32" ^ # --hidden-import "pynput.mouse._win32" ^ # --hidden-import "pystray._win32" ^ # --hidden-import "plyer.platforms.win.notification" ^ # --hidden-import "win32api" ^ # --hidden-import "win32con" ^ # --hidden-import "win32gui" ^ # run_agent_v1.py # # Le .exe resultant sera dans dist/Lea.exe (~50-100 MB) # # ============================================================ # # OPTION ALTERNATIVE : Python Embedded (recommandee) # # Python Embedded est un Python portable officiel (pas d'installation). # Combine avec le code source, c'est la methode la plus fiable # pour les non-informaticiens. # # Sur une machine Windows : # 1. Telecharger Python Embedded 3.12 : # https://www.python.org/ftp/python/3.12.9/python-3.12.9-embed-amd64.zip # # 2. Dezipper dans un dossier temporaire # # 3. Activer pip dans Python Embedded : # - Editer python312._pth, decommenter "import site" # - Telecharger get-pip.py : https://bootstrap.pypa.io/get-pip.py # - Executer : python.exe get-pip.py # # 4. Installer les dependances : # python.exe -m pip install -r requirements_agent.txt # # 5. Copier le code source (agent_v1/, lea_ui/, run_agent_v1.py) # # 6. Zipper le tout → Lea_Portable.zip (~40-60 MB) # # Le Lea.bat dans ce cas utiliserait : # python\python.exe run_agent_v1.py # au lieu de .venv\Scripts\python.exe # # ============================================================ set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" echo "============================================================" echo " Build Lea.exe (PyInstaller)" echo "============================================================" echo "" echo " Ce script ne peut pas produire un .exe Windows depuis Linux." echo "" echo " OPTIONS DISPONIBLES :" echo "" echo " 1. OPTION VIA PC WINDOWS (recommandee pour .exe) :" echo " Copiez le dossier deploy/ sur le PC Windows" echo " puis lancez la commande PyInstaller ci-dessous." echo "" echo " 2. OPTION ZIP + VENV (recommandee pour deploiement rapide) :" echo " Lancez ./deploy/build_package.sh" echo " Le zip resultant contient install.bat + Lea.bat" echo "" echo " 3. OPTION PYTHON EMBEDDED (recommandee pour zero install) :" echo " Suivez les instructions dans ce script (section ALTERNATIVE)" echo "" echo "============================================================" echo "" # Generer le .spec PyInstaller pour reference SPEC_FILE="$SCRIPT_DIR/Lea.spec" cat > "$SPEC_FILE" << 'PYINSTALLER_SPEC' # -*- mode: python ; coding: utf-8 -*- # Lea.spec — Configuration PyInstaller pour l'agent Lea # # Usage sur Windows : # pip install pyinstaller # pyinstaller Lea.spec # # Le .exe resultant sera dans dist/Lea.exe import os import sys block_cipher = None # Repertoire de travail (ou se trouve ce .spec) SPEC_DIR = os.path.dirname(os.path.abspath(SPEC())) if 'SPEC' in dir() else '.' a = Analysis( ['run_agent_v1.py'], pathex=['.'], binaries=[], datas=[ ('agent_v1', 'agent_v1'), ('lea_ui', 'lea_ui'), ('config.txt', '.'), ('LISEZMOI.txt', '.'), ], hiddenimports=[ # pynput backends Windows 'pynput.keyboard._win32', 'pynput.mouse._win32', # pystray backend Windows 'pystray._win32', # plyer notification Windows 'plyer.platforms.win', 'plyer.platforms.win.notification', # pywin32 'win32api', 'win32con', 'win32gui', 'win32com', 'pythoncom', # tkinter (stdlib, parfois manquant dans PyInstaller) 'tkinter', 'tkinter.simpledialog', 'tkinter.messagebox', 'tkinter.filedialog', ], hookspath=[], hooksconfig={}, runtime_hooks=[], excludes=[ # Exclure les modules lourds non necessaires cote client 'torch', 'torchvision', 'transformers', 'clip', 'open_clip', 'faiss', 'cv2', # opencv pas obligatoire (blur_sensitive a un fallback) 'numpy', # requis par PIL mais pas directement 'scipy', 'sklearn', 'matplotlib', 'pandas', 'tensorflow', ], 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, a.binaries, a.zipfiles, a.datas, [], name='Lea', debug=False, bootloader_ignore_signals=False, strip=False, upx=True, upx_exclude=[], runtime_tmpdir=None, console=False, # --windowed : pas de console visible disable_windowed_traceback=False, argv_emulation=False, target_arch=None, codesign_identity=None, entitlements_file=None, # icon='assets/lea_icon.ico', # Decommenter quand l'icone sera creee ) PYINSTALLER_SPEC echo " Fichier Lea.spec genere dans : $SPEC_FILE" echo "" echo " Pour builder sur Windows :" echo " 1. Copier le dossier Lea/ (apres build_package.sh) sur le PC Windows" echo " 2. pip install pyinstaller" echo " 3. cd Lea" echo " 4. pyinstaller ../Lea.spec" echo " 5. Le .exe sera dans dist/Lea.exe" echo "" # Generer aussi un script batch pour builder sur Windows WIN_BUILD="$SCRIPT_DIR/build_exe_windows.bat" cat > "$WIN_BUILD" << 'WIN_BATCH' @echo off chcp 65001 >nul 2>&1 title Build Lea.exe echo ============================================================ echo Build Lea.exe (PyInstaller) echo ============================================================ echo. :: Verifier PyInstaller pip show pyinstaller >nul 2>&1 if errorlevel 1 ( echo Installation de PyInstaller... pip install pyinstaller ) :: Builder echo Build en cours (cela prend 2-5 minutes)... echo. pyinstaller --onefile --windowed ^ --name "Lea" ^ --add-data "agent_v1;agent_v1" ^ --add-data "lea_ui;lea_ui" ^ --add-data "config.txt;." ^ --add-data "LISEZMOI.txt;." ^ --hidden-import "pynput.keyboard._win32" ^ --hidden-import "pynput.mouse._win32" ^ --hidden-import "pystray._win32" ^ --hidden-import "plyer.platforms.win.notification" ^ --hidden-import "win32api" ^ --hidden-import "win32con" ^ --hidden-import "win32gui" ^ --hidden-import "tkinter" ^ --hidden-import "tkinter.simpledialog" ^ --hidden-import "tkinter.messagebox" ^ --exclude-module "torch" ^ --exclude-module "torchvision" ^ --exclude-module "transformers" ^ --exclude-module "clip" ^ --exclude-module "faiss" ^ --exclude-module "scipy" ^ --exclude-module "sklearn" ^ --exclude-module "matplotlib" ^ --exclude-module "pandas" ^ --exclude-module "tensorflow" ^ run_agent_v1.py if errorlevel 1 ( echo. echo ERREUR : Le build a echoue. pause exit /b 1 ) echo. echo ============================================================ echo Build termine ! echo. echo Lea.exe est dans le dossier dist\ echo Taille : dir dist\Lea.exe | findstr "Lea.exe" echo. echo Pour deployer : copiez dist\Lea.exe + config.txt + LISEZMOI.txt echo ============================================================ pause WIN_BATCH echo " Script Windows genere : $WIN_BUILD" echo "" echo "============================================================"