Add Windows build scripts and documentation for single-file executable

This commit is contained in:
Quality App Developer
2026-02-05 14:55:06 +02:00
parent e838d25c44
commit 1536f26fee
3 changed files with 363 additions and 0 deletions

167
BUILD_ON_WINDOWS.md Normal file
View File

@@ -0,0 +1,167 @@
# Building LabelPrinter.exe on Windows
This guide explains how to build a standalone `LabelPrinter.exe` single-file executable on a Windows machine.
## Prerequisites
1. **Python 3.10 or higher** - Download from https://www.python.org/
- ⚠️ **IMPORTANT**: Check "Add Python to PATH" during installation
- Verify: Open Command Prompt and type `python --version`
2. **Git** (optional, for cloning the repository)
3. **Internet connection** - To download dependencies
## Quick Start (Using Provided Scripts)
### Option 1: Batch Script (Recommended for CMD users)
1. Open **Command Prompt** (cmd.exe)
2. Navigate to the project folder:
```
cd C:\path\to\label_print
```
3. Run the build script:
```
build_windows.bat
```
4. Wait 5-15 minutes for the build to complete
5. The executable will be in: `dist\LabelPrinter.exe`
### Option 2: PowerShell Script
1. Open **PowerShell** (as Administrator recommended)
2. Navigate to the project folder:
```
cd C:\path\to\label_print
```
3. Allow script execution (if needed):
```
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
```
4. Run the build script:
```
.\build_windows.ps1
```
5. Wait 5-15 minutes for the build to complete
6. The executable will be in: `dist\LabelPrinter.exe`
## Manual Build Steps
If you prefer to run commands manually:
### Step 1: Prepare Python Environment
```bash
# Upgrade pip, setuptools, and wheel
python -m pip install --upgrade pip setuptools wheel
```
### Step 2: Install Dependencies
```bash
# Install required Python packages
pip install python-barcode pillow reportlab kivy==2.2.1 pyinstaller==6.1.0
```
### Step 3: Build the Executable
```bash
# Create single-file executable
pyinstaller label_printer_gui.py ^
--onefile ^
--windowed ^
--name=LabelPrinter ^
--distpath=./dist ^
--workpath=./build ^
--hidden-import=kivy ^
--hidden-import=PIL ^
--hidden-import=barcode ^
--hidden-import=reportlab ^
--hidden-import=print_label ^
--hidden-import=print_label_pdf ^
-y
```
The build process will take 5-15 minutes depending on your PC speed.
### Step 4: Test the Executable
```bash
# Run the built executable
dist\LabelPrinter.exe
```
## Output
After successful build, you'll have:
```
dist/
└── LabelPrinter.exe ← Single executable file
```
## Distributing the Executable
You can:
1. **Copy `LabelPrinter.exe`** to any Windows PC (no Python needed!)
2. **Share via USB** or file transfer
3. **Create an installer** using NSIS or InnoSetup (optional)
4. **Upload to GitHub Releases** for public distribution
## Troubleshooting
### Error: "Python is not recognized"
- Reinstall Python and check "Add Python to PATH"
- Restart Command Prompt after reinstalling Python
### Error: "pip command not found"
- Use `python -m pip` instead of `pip`
### Build takes too long (>30 minutes)
- **Normal for first build** - Kivy framework is large
- Subsequent builds will be faster due to caching
- Close other applications to free up RAM
### Error: "No module named 'kivy'"
- Make sure dependencies installed correctly: `pip install kivy==2.2.1`
- Check internet connection
### Error: "LabelPrinter.exe won't start"
- Make sure all files are in the project folder:
- `label_printer_gui.py`
- `print_label.py`
- `print_label_pdf.py`
- Antivirus might be blocking it - check security software
## Build Time Reference
- **First build**: 10-15 minutes (downloading dependencies)
- **Subsequent builds**: 5-10 minutes (cached dependencies)
## Advanced Options
### Reduce Build Time
```bash
pyinstaller label_printer_gui.py --onefile --windowed --name=LabelPrinter -y
```
### Add Icon to Executable
```bash
pyinstaller label_printer_gui.py --onefile --windowed --name=LabelPrinter --icon=path\to\icon.ico -y
```
### Faster: Use --onedir (Directory) instead of --onefile
```bash
pyinstaller label_printer_gui.py --onedir --windowed --name=LabelPrinter -y
# Builds in ~3-5 minutes, but creates a folder instead of single file
```
## Support
If you encounter issues:
1. Check the error message carefully
2. Make sure Python 3.10+ is installed
3. Verify all dependencies: `pip list`
4. Check internet connection
5. Try again with a fresh Command Prompt window

98
build_windows.bat Normal file
View File

@@ -0,0 +1,98 @@
@echo off
REM Label Printer - Windows Build Script (Single File EXE)
REM This script builds a standalone LabelPrinter.exe on Windows
REM Requirements: Python 3.10+ installed and in PATH
setlocal enabledelayedexpansion
echo.
echo ========================================================
echo Label Printer - Windows Build Script
echo Creates: LabelPrinter.exe (Single File)
echo ========================================================
echo.
REM Check if Python is installed
python --version >nul 2>&1
if errorlevel 1 (
echo ERROR: Python is not installed or not in PATH
echo Please install Python 3.10+ from https://www.python.org/
echo Make sure to check "Add Python to PATH" during installation
pause
exit /b 1
)
echo [1/5] Checking Python installation...
python --version
echo.
REM Upgrade pip
echo [2/5] Upgrading pip, setuptools, and wheel...
python -m pip install --upgrade pip setuptools wheel
if errorlevel 1 (
echo ERROR: Failed to upgrade pip
pause
exit /b 1
)
echo.
REM Install dependencies
echo [3/5] Installing dependencies...
echo Installing: python-barcode, pillow, reportlab, kivy, pyinstaller...
pip install python-barcode pillow reportlab kivy==2.2.1 pyinstaller==6.1.0
if errorlevel 1 (
echo ERROR: Failed to install dependencies
pause
exit /b 1
)
echo.
REM Clean old build
echo [4/5] Cleaning old build artifacts...
if exist "dist" rmdir /s /q dist
if exist "build" rmdir /s /q build
if exist "*.spec" del *.spec
echo.
REM Build with PyInstaller
echo [5/5] Building executable with PyInstaller...
echo This may take 5-15 minutes, please wait...
echo.
pyinstaller label_printer_gui.py ^
--onefile ^
--windowed ^
--name=LabelPrinter ^
--distpath=./dist ^
--workpath=./build ^
--hidden-import=kivy ^
--hidden-import=PIL ^
--hidden-import=barcode ^
--hidden-import=reportlab ^
--hidden-import=print_label ^
--hidden-import=print_label_pdf ^
-y
if errorlevel 1 (
echo.
echo ERROR: Build failed!
echo Please check the error messages above.
pause
exit /b 1
)
echo.
echo ========================================================
echo BUILD SUCCESSFUL!
echo ========================================================
echo.
echo Executable Location: dist\LabelPrinter.exe
echo.
echo Next steps:
echo 1. Navigate to the dist folder
echo 2. Double-click LabelPrinter.exe to run
echo 3. You can copy LabelPrinter.exe to other machines
echo.
echo Note: First run may take a moment as Kivy initializes
echo.
pause

98
build_windows.ps1 Normal file
View File

@@ -0,0 +1,98 @@
# Label Printer - Windows Build Script (Single File EXE)
# This script builds a standalone LabelPrinter.exe on Windows
# Requirements: Python 3.10+ installed and in PATH
Write-Host ""
Write-Host "========================================================"
Write-Host " Label Printer - Windows Build Script"
Write-Host " Creates: LabelPrinter.exe (Single File)"
Write-Host "========================================================"
Write-Host ""
# Check if Python is installed
try {
$pythonVersion = python --version 2>&1
if ($LASTEXITCODE -ne 0) {
throw "Python not found"
}
} catch {
Write-Host "ERROR: Python is not installed or not in PATH" -ForegroundColor Red
Write-Host "Please install Python 3.10+ from https://www.python.org/"
Write-Host "Make sure to check 'Add Python to PATH' during installation"
Read-Host "Press Enter to exit"
exit 1
}
Write-Host "[1/5] Checking Python installation..." -ForegroundColor Cyan
Write-Host $pythonVersion
Write-Host ""
Write-Host "[2/5] Upgrading pip, setuptools, and wheel..." -ForegroundColor Cyan
python -m pip install --upgrade pip setuptools wheel
if ($LASTEXITCODE -ne 0) {
Write-Host "ERROR: Failed to upgrade pip" -ForegroundColor Red
Read-Host "Press Enter to exit"
exit 1
}
Write-Host ""
Write-Host "[3/5] Installing dependencies..." -ForegroundColor Cyan
Write-Host "Installing: python-barcode, pillow, reportlab, kivy, pyinstaller..."
pip install python-barcode pillow reportlab kivy==2.2.1 pyinstaller==6.1.0
if ($LASTEXITCODE -ne 0) {
Write-Host "ERROR: Failed to install dependencies" -ForegroundColor Red
Read-Host "Press Enter to exit"
exit 1
}
Write-Host ""
Write-Host "[4/5] Cleaning old build artifacts..." -ForegroundColor Cyan
if (Test-Path "dist") { Remove-Item -Recurse -Force "dist" }
if (Test-Path "build") { Remove-Item -Recurse -Force "build" }
Remove-Item -Force "*.spec" -ErrorAction SilentlyContinue
Write-Host ""
Write-Host "[5/5] Building executable with PyInstaller..." -ForegroundColor Cyan
Write-Host "This may take 5-15 minutes, please wait..."
Write-Host ""
$pyinstallerArgs = @(
"label_printer_gui.py",
"--onefile",
"--windowed",
"--name=LabelPrinter",
"--distpath=./dist",
"--workpath=./build",
"--hidden-import=kivy",
"--hidden-import=PIL",
"--hidden-import=barcode",
"--hidden-import=reportlab",
"--hidden-import=print_label",
"--hidden-import=print_label_pdf",
"-y"
)
pyinstaller @pyinstallerArgs
if ($LASTEXITCODE -ne 0) {
Write-Host ""
Write-Host "ERROR: Build failed!" -ForegroundColor Red
Write-Host "Please check the error messages above." -ForegroundColor Red
Read-Host "Press Enter to exit"
exit 1
}
Write-Host ""
Write-Host "========================================================"
Write-Host " BUILD SUCCESSFUL!" -ForegroundColor Green
Write-Host "========================================================"
Write-Host ""
Write-Host "Executable Location: dist\LabelPrinter.exe" -ForegroundColor Green
Write-Host ""
Write-Host "Next steps:"
Write-Host " 1. Navigate to the dist folder"
Write-Host " 2. Double-click LabelPrinter.exe to run"
Write-Host " 3. You can copy LabelPrinter.exe to other machines"
Write-Host ""
Write-Host "Note: First run may take a moment as Kivy initializes"
Write-Host ""
Read-Host "Press Enter to exit"