Compilation .exe PyInstaller + fix chemins resources
- L'installation compile maintenant un vrai .exe autonome - Les raccourcis Bureau/Menu Demarrer pointent vers le .exe - Support PyInstaller pour les chemins resources (logo, icone) - La mise a jour recompile aussi le .exe - Fallback lanceur .vbs si compilation echoue Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
119
install.bat
119
install.bat
@@ -61,13 +61,15 @@ if exist "%INSTALL_DIR%\app\main.py" (
|
||||
)
|
||||
|
||||
:: Creer le repertoire d'installation
|
||||
echo [1/7] Creation du repertoire d'installation...
|
||||
set "EXE_PATH=%INSTALL_DIR%\CopydevImposingTool.exe"
|
||||
|
||||
echo [1/8] Creation du repertoire d'installation...
|
||||
if not exist "%INSTALL_DIR%" mkdir "%INSTALL_DIR%"
|
||||
if not exist "%INSTALL_DIR%\temp" mkdir "%INSTALL_DIR%\temp"
|
||||
|
||||
:: ---- GIT ----
|
||||
:INSTALL_GIT
|
||||
echo [2/7] Verification de Git...
|
||||
echo [2/8] Verification de Git...
|
||||
where git >nul 2>&1
|
||||
if %ERRORLEVEL%==0 (
|
||||
echo Git est deja installe.
|
||||
@@ -99,7 +101,7 @@ echo Git portable installe.
|
||||
|
||||
:: ---- PYTHON ----
|
||||
:INSTALL_PYTHON
|
||||
echo [3/7] Verification de Python...
|
||||
echo [3/8] Verification de Python...
|
||||
|
||||
:: Verifier Python systeme
|
||||
where python >nul 2>&1
|
||||
@@ -138,7 +140,7 @@ echo Python %PYTHON_VERSION% embarque installe.
|
||||
|
||||
:: ---- PIP ----
|
||||
:INSTALL_PIP
|
||||
echo [4/7] Verification de pip...
|
||||
echo [4/8] Verification de pip...
|
||||
"%PYTHON_CMD%" -m pip --version >nul 2>&1
|
||||
if %ERRORLEVEL%==0 (
|
||||
echo pip est deja installe.
|
||||
@@ -153,13 +155,13 @@ echo pip installe.
|
||||
|
||||
:: ---- DEPENDANCES ----
|
||||
:INSTALL_DEPS
|
||||
echo [5/7] Installation des dependances Python...
|
||||
"%PYTHON_CMD%" -m pip install --upgrade --no-warn-script-location PyQt6 pypdf reportlab pypdfium2 2>&1 | findstr /i "Successfully already"
|
||||
echo [5/8] Installation des dependances Python...
|
||||
"%PYTHON_CMD%" -m pip install --upgrade --no-warn-script-location PyQt6 pypdf reportlab pypdfium2 pyinstaller 2>&1 | findstr /i "Successfully already"
|
||||
echo Dependances installees.
|
||||
|
||||
:: ---- CODE SOURCE ----
|
||||
:INSTALL_CODE
|
||||
echo [6/7] Telechargement du code source...
|
||||
echo [6/8] Telechargement du code source...
|
||||
if exist "%APP_DIR%\.git" (
|
||||
echo Mise a jour du code existant...
|
||||
pushd "%APP_DIR%"
|
||||
@@ -177,34 +179,60 @@ if not exist "%APP_DIR%\main.py" (
|
||||
)
|
||||
echo Code source telecharge.
|
||||
|
||||
:: ---- COMPILATION EXE ----
|
||||
:INSTALL_BUILD
|
||||
echo [7/8] Compilation de l'executable...
|
||||
echo (cette etape peut prendre quelques minutes)
|
||||
pushd "%APP_DIR%"
|
||||
"%PYTHON_CMD%" -m PyInstaller --onefile --noconsole --name CopydevImposingTool ^
|
||||
--icon "%APP_DIR%\resources\logo.png" ^
|
||||
--add-data "resources;resources" ^
|
||||
--hidden-import pypdf ^
|
||||
--hidden-import reportlab ^
|
||||
--hidden-import reportlab.pdfgen ^
|
||||
--hidden-import reportlab.pdfgen.canvas ^
|
||||
--hidden-import reportlab.lib ^
|
||||
--hidden-import reportlab.lib.pagesizes ^
|
||||
--hidden-import reportlab.lib.units ^
|
||||
--hidden-import reportlab.lib.colors ^
|
||||
--hidden-import pypdfium2 ^
|
||||
--hidden-import pypdfium2._helpers ^
|
||||
--distpath "%INSTALL_DIR%" ^
|
||||
--workpath "%INSTALL_DIR%\temp\build" ^
|
||||
--specpath "%INSTALL_DIR%\temp" ^
|
||||
main.py >nul 2>&1
|
||||
popd
|
||||
|
||||
if not exist "%EXE_PATH%" (
|
||||
echo [!] La compilation a echoue. Utilisation du lanceur Python.
|
||||
:: Fallback : lanceur .vbs
|
||||
(
|
||||
echo Set WshShell = CreateObject^("WScript.Shell"^)
|
||||
echo WshShell.CurrentDirectory = "%APP_DIR%"
|
||||
echo WshShell.Run """%PYTHON_CMD%"" ""%APP_DIR%\main.py""", 0, False
|
||||
) > "%INSTALL_DIR%\lancer.vbs"
|
||||
set "LAUNCH_TARGET=%INSTALL_DIR%\lancer.vbs"
|
||||
set "LAUNCH_ICON="
|
||||
) else (
|
||||
echo Executable compile : CopydevImposingTool.exe
|
||||
set "LAUNCH_TARGET=%EXE_PATH%"
|
||||
set "LAUNCH_ICON=%EXE_PATH%"
|
||||
)
|
||||
|
||||
:: ---- RACCOURCIS ----
|
||||
:INSTALL_SHORTCUTS
|
||||
echo [7/7] Creation des raccourcis...
|
||||
|
||||
:: Creer le lanceur .bat
|
||||
(
|
||||
echo @echo off
|
||||
echo cd /d "%APP_DIR%"
|
||||
echo "%PYTHON_CMD%" main.py
|
||||
) > "%INSTALL_DIR%\lancer.bat"
|
||||
|
||||
:: Creer le lanceur .vbs (sans fenetre console)
|
||||
(
|
||||
echo Set WshShell = CreateObject^("WScript.Shell"^)
|
||||
echo WshShell.CurrentDirectory = "%APP_DIR%"
|
||||
echo WshShell.Run """%PYTHON_CMD%"" ""%APP_DIR%\main.py""", 0, False
|
||||
) > "%INSTALL_DIR%\lancer.vbs"
|
||||
echo [8/8] Creation des raccourcis...
|
||||
|
||||
:: Raccourci Bureau
|
||||
powershell -Command "& { $WshShell = New-Object -ComObject WScript.Shell; $Shortcut = $WshShell.CreateShortcut([Environment]::GetFolderPath('Desktop') + '\%SHORTCUT_NAME%.lnk'); $Shortcut.TargetPath = '%INSTALL_DIR%\lancer.vbs'; $Shortcut.WorkingDirectory = '%APP_DIR%'; $Shortcut.Description = '%APP_NAME%'; $Shortcut.Save() }" 2>nul
|
||||
powershell -Command "& { $WshShell = New-Object -ComObject WScript.Shell; $Shortcut = $WshShell.CreateShortcut([Environment]::GetFolderPath('Desktop') + '\%SHORTCUT_NAME%.lnk'); $Shortcut.TargetPath = '%LAUNCH_TARGET%'; $Shortcut.WorkingDirectory = '%INSTALL_DIR%'; $Shortcut.Description = '%APP_NAME%'; if ('%LAUNCH_ICON%' -ne '') { $Shortcut.IconLocation = '%LAUNCH_ICON%,0' }; $Shortcut.Save() }" 2>nul
|
||||
echo Raccourci Bureau cree.
|
||||
|
||||
:: Raccourci Menu Demarrer
|
||||
set "START_MENU=%APPDATA%\Microsoft\Windows\Start Menu\Programs"
|
||||
powershell -Command "& { $WshShell = New-Object -ComObject WScript.Shell; $Shortcut = $WshShell.CreateShortcut('%START_MENU%\%SHORTCUT_NAME%.lnk'); $Shortcut.TargetPath = '%INSTALL_DIR%\lancer.vbs'; $Shortcut.WorkingDirectory = '%APP_DIR%'; $Shortcut.Description = '%APP_NAME%'; $Shortcut.Save() }" 2>nul
|
||||
powershell -Command "& { $WshShell = New-Object -ComObject WScript.Shell; $Shortcut = $WshShell.CreateShortcut('%START_MENU%\%SHORTCUT_NAME%.lnk'); $Shortcut.TargetPath = '%LAUNCH_TARGET%'; $Shortcut.WorkingDirectory = '%INSTALL_DIR%'; $Shortcut.Description = '%APP_NAME%'; if ('%LAUNCH_ICON%' -ne '') { $Shortcut.IconLocation = '%LAUNCH_ICON%,0' }; $Shortcut.Save() }" 2>nul
|
||||
echo Raccourci Menu Demarrer cree.
|
||||
|
||||
:: Nettoyer temp
|
||||
:: Nettoyer temp et fichiers de build
|
||||
rmdir /s /q "%INSTALL_DIR%\temp" 2>nul
|
||||
|
||||
:: ---- FIN INSTALLATION ----
|
||||
@@ -213,9 +241,12 @@ echo ============================================================
|
||||
echo INSTALLATION TERMINEE
|
||||
echo ============================================================
|
||||
echo.
|
||||
echo Dossier : %INSTALL_DIR%
|
||||
echo Lanceur : Double-cliquez sur le raccourci Bureau
|
||||
echo "%SHORTCUT_NAME%"
|
||||
echo Dossier : %INSTALL_DIR%
|
||||
if exist "%EXE_PATH%" (
|
||||
echo Executable: CopydevImposingTool.exe
|
||||
)
|
||||
echo Lanceur : Raccourci Bureau ou Menu Demarrer
|
||||
echo "%SHORTCUT_NAME%"
|
||||
echo.
|
||||
echo Mot de passe requis au lancement.
|
||||
echo.
|
||||
@@ -285,10 +316,36 @@ echo.
|
||||
popd
|
||||
echo Code mis a jour.
|
||||
|
||||
echo [2/3] Mise a jour des dependances...
|
||||
"%PYTHON_CMD%" -m pip install --upgrade --no-warn-script-location PyQt6 pypdf reportlab pypdfium2 2>&1 | findstr /i "Successfully already"
|
||||
echo [2/4] Mise a jour des dependances...
|
||||
"%PYTHON_CMD%" -m pip install --upgrade --no-warn-script-location PyQt6 pypdf reportlab pypdfium2 pyinstaller 2>&1 | findstr /i "Successfully already"
|
||||
|
||||
echo [3/3] Termine !
|
||||
echo [3/4] Recompilation de l'executable...
|
||||
pushd "%APP_DIR%"
|
||||
"%PYTHON_CMD%" -m PyInstaller --onefile --noconsole --name CopydevImposingTool ^
|
||||
--add-data "resources;resources" ^
|
||||
--hidden-import pypdf ^
|
||||
--hidden-import reportlab ^
|
||||
--hidden-import reportlab.pdfgen ^
|
||||
--hidden-import reportlab.pdfgen.canvas ^
|
||||
--hidden-import reportlab.lib ^
|
||||
--hidden-import reportlab.lib.pagesizes ^
|
||||
--hidden-import reportlab.lib.units ^
|
||||
--hidden-import reportlab.lib.colors ^
|
||||
--hidden-import pypdfium2 ^
|
||||
--hidden-import pypdfium2._helpers ^
|
||||
--distpath "%INSTALL_DIR%" ^
|
||||
--workpath "%INSTALL_DIR%\temp\build" ^
|
||||
--specpath "%INSTALL_DIR%\temp" ^
|
||||
main.py >nul 2>&1
|
||||
popd
|
||||
rmdir /s /q "%INSTALL_DIR%\temp" 2>nul
|
||||
if exist "%INSTALL_DIR%\CopydevImposingTool.exe" (
|
||||
echo Executable recompile.
|
||||
) else (
|
||||
echo [!] Compilation echouee, l'ancienne version reste active.
|
||||
)
|
||||
|
||||
echo [4/4] Termine !
|
||||
echo.
|
||||
echo ============================================================
|
||||
echo MISE A JOUR TERMINEE
|
||||
|
||||
Reference in New Issue
Block a user