Compare commits
12 Commits
5e1cdfb9e5
...
9f45a02f13
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9f45a02f13 | ||
|
|
6f07bb9cba | ||
|
|
1536f26fee | ||
|
|
e838d25c44 | ||
|
|
8e3893e85c | ||
|
|
f2a2ca7d97 | ||
|
|
8301fc8ef4 | ||
|
|
82949fb9bf | ||
|
|
9bfc40d733 | ||
|
|
e7aac91d51 | ||
|
|
795dd5cac2 | ||
|
|
ba54bbfa75 |
178
BUILD_ON_WINDOWS.md
Normal file
178
BUILD_ON_WINDOWS.md
Normal file
@@ -0,0 +1,178 @@
|
|||||||
|
# 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, 3.11, 3.12, or 3.13** - Download from https://www.python.org/
|
||||||
|
- ⚠️ **IMPORTANT**: Check "Add Python to PATH" during installation
|
||||||
|
- ⚠️ **Note**: Python 3.14+ may have compatibility issues with Kivy 2.2.1
|
||||||
|
- 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
|
||||||
|
|
||||||
|
### Python 3.14 Compatibility Issues
|
||||||
|
If you have Python 3.14 installed and get errors like:
|
||||||
|
- `ModuleNotFoundError: No module named 'kivy'`
|
||||||
|
- `ImportError: DLL load failed`
|
||||||
|
- PyInstaller compatibility errors
|
||||||
|
|
||||||
|
**Solution:**
|
||||||
|
- Install Python 3.11, 3.12, or 3.13 instead
|
||||||
|
- Download from: https://www.python.org/downloads/
|
||||||
|
- Uninstall Python 3.14 first
|
||||||
|
- Then use one of the recommended versions
|
||||||
|
- 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
|
||||||
46
build_exe.py
46
build_exe.py
@@ -1,11 +1,20 @@
|
|||||||
"""
|
"""
|
||||||
PyInstaller build script for Label Printer GUI
|
PyInstaller build script for Label Printer GUI
|
||||||
Run this to create a standalone Windows executable
|
Run this to create a standalone Windows executable
|
||||||
|
|
||||||
|
IMPORTANT: This script MUST be run on Windows to generate a Windows .exe file.
|
||||||
|
If run on Linux/macOS, it will create a Linux/macOS binary that won't work on Windows.
|
||||||
|
|
||||||
|
To build for Windows:
|
||||||
|
1. Copy this project to a Windows machine
|
||||||
|
2. Install dependencies: pip install -r requirements_windows.txt
|
||||||
|
3. Run this script: python build_exe.py
|
||||||
|
4. The Windows .exe will be created in the dist/ folder
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from PyInstaller import __main__ as pyi_main
|
import subprocess
|
||||||
|
|
||||||
# Get the current directory
|
# Get the current directory
|
||||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
@@ -17,7 +26,7 @@ args = [
|
|||||||
'--windowed', # Don't show console window
|
'--windowed', # Don't show console window
|
||||||
'--name=LabelPrinter', # Executable name
|
'--name=LabelPrinter', # Executable name
|
||||||
'--distpath=./dist', # Output directory
|
'--distpath=./dist', # Output directory
|
||||||
'--buildpath=./build', # Build directory
|
'--workpath=./build', # Work directory (was --buildpath)
|
||||||
'--hidden-import=kivy',
|
'--hidden-import=kivy',
|
||||||
'--hidden-import=kivy.core.window',
|
'--hidden-import=kivy.core.window',
|
||||||
'--hidden-import=kivy.core.text',
|
'--hidden-import=kivy.core.text',
|
||||||
@@ -49,15 +58,26 @@ if __name__ == '__main__':
|
|||||||
# Change to script directory
|
# Change to script directory
|
||||||
os.chdir(script_dir)
|
os.chdir(script_dir)
|
||||||
|
|
||||||
# Run PyInstaller
|
# Run PyInstaller directly with subprocess for better error reporting
|
||||||
pyi_main.run(args)
|
try:
|
||||||
|
result = subprocess.run(['pyinstaller'] + args, check=True)
|
||||||
|
|
||||||
print("\n" + "=" * 60)
|
print("\n" + "=" * 60)
|
||||||
print("Build Complete!")
|
print("Build Complete!")
|
||||||
print("=" * 60)
|
print("=" * 60)
|
||||||
print("\nExecutable location: ./dist/LabelPrinter.exe")
|
print("\nExecutable location: ./dist/LabelPrinter.exe")
|
||||||
print("\nYou can now:")
|
print("\nYou can now:")
|
||||||
print("1. Double-click LabelPrinter.exe to run")
|
print("1. Double-click LabelPrinter.exe to run")
|
||||||
print("2. Share the exe with others")
|
print("2. Share the exe with others")
|
||||||
print("3. Create a shortcut on desktop")
|
print("3. Create a shortcut on desktop")
|
||||||
print("\nNote: First run may take a moment as Kivy initializes")
|
print("\nNote: First run may take a moment as Kivy initializes")
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
print("\n" + "=" * 60)
|
||||||
|
print("Build Failed!")
|
||||||
|
print("=" * 60)
|
||||||
|
print(f"\nError code: {e.returncode}")
|
||||||
|
print("\nPlease check the error messages above for details.")
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"\nFatal error: {e}")
|
||||||
|
sys.exit(1)
|
||||||
|
|||||||
99
build_windows.bat
Normal file
99
build_windows.bat
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
@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-3.13 installed and in PATH
|
||||||
|
REM Note: Python 3.14+ may have compatibility issues
|
||||||
|
|
||||||
|
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-3.13 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
|
||||||
99
build_windows.ps1
Normal file
99
build_windows.ps1
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
# Label Printer - Windows Build Script (Single File EXE)
|
||||||
|
# This script builds a standalone LabelPrinter.exe on Windows
|
||||||
|
# Requirements: Python 3.10-3.13 installed and in PATH
|
||||||
|
# Note: Python 3.14+ may have compatibility issues
|
||||||
|
|
||||||
|
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-3.13 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"
|
||||||
5
requirements_windows.txt
Normal file
5
requirements_windows.txt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
python-barcode
|
||||||
|
pillow
|
||||||
|
kivy>=2.1.0
|
||||||
|
reportlab
|
||||||
|
pyinstaller>=6.0.0
|
||||||
Reference in New Issue
Block a user