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:
@@ -38,9 +38,10 @@ class MainWindow(QMainWindow):
|
|||||||
self.setMinimumSize(1000, 700)
|
self.setMinimumSize(1000, 700)
|
||||||
|
|
||||||
# Icone de la fenetre
|
# Icone de la fenetre
|
||||||
|
import sys as _sys
|
||||||
from PyQt6.QtGui import QIcon
|
from PyQt6.QtGui import QIcon
|
||||||
icon_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
|
_base = _sys._MEIPASS if getattr(_sys, 'frozen', False) else os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
"resources", "logo.png")
|
icon_path = os.path.join(_base, "resources", "logo.png")
|
||||||
if os.path.exists(icon_path):
|
if os.path.exists(icon_path):
|
||||||
self.setWindowIcon(QIcon(icon_path))
|
self.setWindowIcon(QIcon(icon_path))
|
||||||
self._current_file = None
|
self._current_file = None
|
||||||
@@ -349,8 +350,9 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
# Logo
|
# Logo
|
||||||
logo_label = QLabel()
|
logo_label = QLabel()
|
||||||
logo_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
|
import sys as _sys
|
||||||
"resources", "logo.png")
|
_base = _sys._MEIPASS if getattr(_sys, 'frozen', False) else os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
logo_path = os.path.join(_base, "resources", "logo.png")
|
||||||
if os.path.exists(logo_path):
|
if os.path.exists(logo_path):
|
||||||
pixmap = QPixmap(logo_path).scaled(120, 120, Qt.AspectRatioMode.KeepAspectRatio,
|
pixmap = QPixmap(logo_path).scaled(120, 120, Qt.AspectRatioMode.KeepAspectRatio,
|
||||||
Qt.TransformationMode.SmoothTransformation)
|
Qt.TransformationMode.SmoothTransformation)
|
||||||
|
|||||||
119
install.bat
119
install.bat
@@ -61,13 +61,15 @@ if exist "%INSTALL_DIR%\app\main.py" (
|
|||||||
)
|
)
|
||||||
|
|
||||||
:: Creer le repertoire d'installation
|
:: 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%" mkdir "%INSTALL_DIR%"
|
||||||
if not exist "%INSTALL_DIR%\temp" mkdir "%INSTALL_DIR%\temp"
|
if not exist "%INSTALL_DIR%\temp" mkdir "%INSTALL_DIR%\temp"
|
||||||
|
|
||||||
:: ---- GIT ----
|
:: ---- GIT ----
|
||||||
:INSTALL_GIT
|
:INSTALL_GIT
|
||||||
echo [2/7] Verification de Git...
|
echo [2/8] Verification de Git...
|
||||||
where git >nul 2>&1
|
where git >nul 2>&1
|
||||||
if %ERRORLEVEL%==0 (
|
if %ERRORLEVEL%==0 (
|
||||||
echo Git est deja installe.
|
echo Git est deja installe.
|
||||||
@@ -99,7 +101,7 @@ echo Git portable installe.
|
|||||||
|
|
||||||
:: ---- PYTHON ----
|
:: ---- PYTHON ----
|
||||||
:INSTALL_PYTHON
|
:INSTALL_PYTHON
|
||||||
echo [3/7] Verification de Python...
|
echo [3/8] Verification de Python...
|
||||||
|
|
||||||
:: Verifier Python systeme
|
:: Verifier Python systeme
|
||||||
where python >nul 2>&1
|
where python >nul 2>&1
|
||||||
@@ -138,7 +140,7 @@ echo Python %PYTHON_VERSION% embarque installe.
|
|||||||
|
|
||||||
:: ---- PIP ----
|
:: ---- PIP ----
|
||||||
:INSTALL_PIP
|
:INSTALL_PIP
|
||||||
echo [4/7] Verification de pip...
|
echo [4/8] Verification de pip...
|
||||||
"%PYTHON_CMD%" -m pip --version >nul 2>&1
|
"%PYTHON_CMD%" -m pip --version >nul 2>&1
|
||||||
if %ERRORLEVEL%==0 (
|
if %ERRORLEVEL%==0 (
|
||||||
echo pip est deja installe.
|
echo pip est deja installe.
|
||||||
@@ -153,13 +155,13 @@ echo pip installe.
|
|||||||
|
|
||||||
:: ---- DEPENDANCES ----
|
:: ---- DEPENDANCES ----
|
||||||
:INSTALL_DEPS
|
:INSTALL_DEPS
|
||||||
echo [5/7] Installation des dependances Python...
|
echo [5/8] Installation des dependances Python...
|
||||||
"%PYTHON_CMD%" -m pip install --upgrade --no-warn-script-location PyQt6 pypdf reportlab pypdfium2 2>&1 | findstr /i "Successfully already"
|
"%PYTHON_CMD%" -m pip install --upgrade --no-warn-script-location PyQt6 pypdf reportlab pypdfium2 pyinstaller 2>&1 | findstr /i "Successfully already"
|
||||||
echo Dependances installees.
|
echo Dependances installees.
|
||||||
|
|
||||||
:: ---- CODE SOURCE ----
|
:: ---- CODE SOURCE ----
|
||||||
:INSTALL_CODE
|
:INSTALL_CODE
|
||||||
echo [6/7] Telechargement du code source...
|
echo [6/8] Telechargement du code source...
|
||||||
if exist "%APP_DIR%\.git" (
|
if exist "%APP_DIR%\.git" (
|
||||||
echo Mise a jour du code existant...
|
echo Mise a jour du code existant...
|
||||||
pushd "%APP_DIR%"
|
pushd "%APP_DIR%"
|
||||||
@@ -177,34 +179,60 @@ if not exist "%APP_DIR%\main.py" (
|
|||||||
)
|
)
|
||||||
echo Code source telecharge.
|
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 ----
|
:: ---- RACCOURCIS ----
|
||||||
:INSTALL_SHORTCUTS
|
:INSTALL_SHORTCUTS
|
||||||
echo [7/7] Creation des raccourcis...
|
echo [8/8] 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"
|
|
||||||
|
|
||||||
:: Raccourci Bureau
|
:: 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.
|
echo Raccourci Bureau cree.
|
||||||
|
|
||||||
:: Raccourci Menu Demarrer
|
:: Raccourci Menu Demarrer
|
||||||
set "START_MENU=%APPDATA%\Microsoft\Windows\Start Menu\Programs"
|
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.
|
echo Raccourci Menu Demarrer cree.
|
||||||
|
|
||||||
:: Nettoyer temp
|
:: Nettoyer temp et fichiers de build
|
||||||
rmdir /s /q "%INSTALL_DIR%\temp" 2>nul
|
rmdir /s /q "%INSTALL_DIR%\temp" 2>nul
|
||||||
|
|
||||||
:: ---- FIN INSTALLATION ----
|
:: ---- FIN INSTALLATION ----
|
||||||
@@ -213,9 +241,12 @@ echo ============================================================
|
|||||||
echo INSTALLATION TERMINEE
|
echo INSTALLATION TERMINEE
|
||||||
echo ============================================================
|
echo ============================================================
|
||||||
echo.
|
echo.
|
||||||
echo Dossier : %INSTALL_DIR%
|
echo Dossier : %INSTALL_DIR%
|
||||||
echo Lanceur : Double-cliquez sur le raccourci Bureau
|
if exist "%EXE_PATH%" (
|
||||||
echo "%SHORTCUT_NAME%"
|
echo Executable: CopydevImposingTool.exe
|
||||||
|
)
|
||||||
|
echo Lanceur : Raccourci Bureau ou Menu Demarrer
|
||||||
|
echo "%SHORTCUT_NAME%"
|
||||||
echo.
|
echo.
|
||||||
echo Mot de passe requis au lancement.
|
echo Mot de passe requis au lancement.
|
||||||
echo.
|
echo.
|
||||||
@@ -285,10 +316,36 @@ echo.
|
|||||||
popd
|
popd
|
||||||
echo Code mis a jour.
|
echo Code mis a jour.
|
||||||
|
|
||||||
echo [2/3] Mise a jour des dependances...
|
echo [2/4] 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"
|
"%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 ============================================================
|
echo ============================================================
|
||||||
echo MISE A JOUR TERMINEE
|
echo MISE A JOUR TERMINEE
|
||||||
|
|||||||
13
main.py
13
main.py
@@ -5,8 +5,15 @@ import sys
|
|||||||
import os
|
import os
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
# Ajouter le repertoire racine au path
|
# Support PyInstaller (chemin des resources)
|
||||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
if getattr(sys, 'frozen', False):
|
||||||
|
BASE_DIR = os.path.dirname(sys.executable)
|
||||||
|
BUNDLE_DIR = sys._MEIPASS
|
||||||
|
else:
|
||||||
|
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
BUNDLE_DIR = BASE_DIR
|
||||||
|
|
||||||
|
sys.path.insert(0, BUNDLE_DIR)
|
||||||
|
|
||||||
from PyQt6.QtWidgets import QApplication, QInputDialog, QMessageBox, QLineEdit
|
from PyQt6.QtWidgets import QApplication, QInputDialog, QMessageBox, QLineEdit
|
||||||
|
|
||||||
@@ -44,7 +51,7 @@ def main():
|
|||||||
|
|
||||||
# Icone application
|
# Icone application
|
||||||
from PyQt6.QtGui import QIcon
|
from PyQt6.QtGui import QIcon
|
||||||
icon_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "resources", "logo.png")
|
icon_path = os.path.join(BUNDLE_DIR, "resources", "logo.png")
|
||||||
if os.path.exists(icon_path):
|
if os.path.exists(icon_path):
|
||||||
app.setWindowIcon(QIcon(icon_path))
|
app.setWindowIcon(QIcon(icon_path))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user