This guide explains how to build a DEB package for UPK (Ubuntu Package Kit) using PyInstaller to create a standalone executable.
The packaging process creates a Python package and packages it into a DEB file that can be installed on Ubuntu/Debian systems. This approach has several advantages:
- Small package size: Only includes source code and metadata (~30KB)
- System integration: Uses system Python and dependencies
- Easy installation: Users can install with
sudo dpkg -i upk-{version}.deb - CLI-optimized: No desktop integration (suitable for command-line tools)
- Maintainable: Standard Python package structure
- Python 3.10 or higher
- pip
- dpkg-deb (usually pre-installed on Ubuntu/Debian)
-
Make the build script executable:
chmod +x build.sh
-
Run the build script:
./build.sh
-
Install the package:
sudo dpkg -i upk-{version}.deb
- Copies source files to the proper Python package structure
- Creates a wrapper script that executes the Python module
- Creates the DEB package structure with proper directory layout
- Generates package metadata including control file and documentation
- Builds the final DEB package using dpkg-deb
The resulting DEB package includes:
- Executable:
/usr/bin/upk- The main UPK application - Shell Completion:
/usr/share/bash-completion/completions/upk- Automatic Bash autocomplete - Managed AppImages: Stored in the location defined by
path_appimages(default~/.local/share/applications/AppImages) - Documentation:
/usr/share/doc/upk/- Package documentation and license - Post-installation script: Handles setup tasks after installation
python3 (>= 3.10)- Python interpreter (for compatibility)python3-click (>= 8.1.0)- Command-line interface librarypython3-rich (>= 13.0.0)- Rich text formatting library
apt- APT package managersnapd- Snap package managerflatpak- Flatpak package managerpacstall- Pacstall package manageram- AppMan package manager
sudo dpkg -i upk-{version}.debsudo apt install -fupk --helpsudo dpkg -r upkupk-debian/
├── DEBIAN/
│ ├── control # Package metadata
│ ├── postinst # Post-installation script
│ └── postrm # Post-removal script
├── usr/
│ ├── bin/
│ │ └── upk # Main executable
│ └── share/
│ └── doc/
│ └── upk/ # Documentation
│ ├── changelog.Debian
│ ├── copyright
│ └── README.Debian
PyInstaller not found: The script automatically creates a virtual environment and installs PyInstaller.
Missing dependencies: The script installs click and rich dependencies in the virtual environment.
Permission errors: Ensure you're not running as root during the build process.
Missing dependencies: Run sudo apt install -f to install missing dependencies.
Architecture mismatch: The package is built for amd64 architecture. For other architectures, you'll need to build on the target system.
Executable not found: Ensure the package was installed correctly with which upk.
Missing system tools: Install recommended packages for full functionality:
sudo apt install apt snapd flatpak pacstallEdit the following in build.sh:
- Maintainer information: Update the maintainer name and email in the control file
- Package version: Modify the version number
- Description: Update the package description
- Dependencies: Adjust dependencies based on your requirements
- PyInstaller options: Modify PyInstaller flags in the build command
- Included files: Update the
--add-dataflags to include additional files - Package structure: Modify the directory structure as needed
-
Clean previous builds:
rm -f upk-{version}.deb dist/upk build/ -rf -
Rebuild:
./build.sh
-
Test installation in a clean environment or virtual machine
- PyInstaller warnings: Check the build output for any warnings
- Package contents: Use
dpkg-deb --contents upk-{version}.debto verify contents - Installation logs: Check system logs during installation
- The executable is self-contained and doesn't require additional Python packages
- The post-installation script runs with root privileges during installation
- All dependencies are bundled, reducing attack surface from external packages
- Package size: ~30KB (source code only)
- Startup time: Standard Python startup time
- Memory usage: Standard Python memory usage
- Dependencies: Uses system-installed packages
For issues with the DEB package:
- Check the troubleshooting section above
- Verify your system meets the requirements
- Test with a clean installation
- Report issues with build output and system information
The DEB packaging scripts and documentation are provided under the same license as the main UPK project.