Demo RPM builder for python packages
Clone repo
git clone https://github.com/mbrav/rpm-python-pack.git && \
cd rpm-python-pack/
Pyinstaller is by far the best option as it packages all script's dependencies into a binary file that takes up many times less space than a regular python package with all its dependencies.
-
Install PyInstaller
pip3 install pyinstaller
-
Build package
pyinstaller cli.py --name python-pack-script --onefile
-
Run binary
./dist/python-pack-script
✅ You should see output:
This is python-pack-script v0.0.7!
-
Install rpm package tools
sudo dnf install -y rpmdevtools rpmlint
-
Build with Python's standard rpm build tool
python3 setup.py bdist --formats=rpm
python3 setup.py bdist_wheel --universal
ℹ️ Convert pyproject.toml to setup.py
pip3 install poetry2setup --user && \ poetry2setup > setup.py
-
Install package:
sudo dnf localinstall dist/python-pack-script-*.noarch.rpm
-
Check package info
rpm -qi python-pack-script && which python-pack-script
✅ You should see info about package like so
Name : python-pack-script Version : 0.0.7 Release : 1 Architecture: noarch Install Date: Wed 27 Apr 2022 09:15:34 AM UTC Group : Development/Libraries Size : 1155 License : UNKNOWN Signature : (none) Source RPM : python-pack-script-0.0.7-1.src.rpm Build Date : Wed 27 Apr 2022 09:11:18 AM UTC Build Host : rocky.local Relocations : /usr Vendor : mbrav <mbrav@protonmail.com> Summary : Demo RPM builder for python packages Description : UNKNOWN
-
Run package
python-pack-script --help
✅ You should see output
This is python-pack-script v0.0.7!
✏️ Notes
Setup rpmbuild folder
rpmdev-setuptree
It will create the following folder in your home directory:
rpmbuild/
├── BUILD
├── RPMS
├── SOURCES
├── SPECS
└── SRPMS
Build spec:
rpmbuild -ba ./build/bdist.linux-x86_64/rpm/SPECS/python-pack-script.spec
This uses the new PEP 518 pyproject.yml standard, but a standard process for building rpm packages seems to yet be established
-
Install poetry
-
Build Python package
poetry build
ℹ️ Install package with pip
Create a new python environment and activate it
python3 -m venv venv && source venv/bin/activate
Install script into environment
pip3 install --no-cache-dir --force-reinstall \ dist/python_pack_script-*-py3-none-any.whl
-
Run script
python -m python_pack_script --help
✅ You should see a print in your terminal
- Using PyInstaller to Easily Distribute Python Applications by Luke Lee
- How to create a Linux RPM package by Valentin Bajrami (Red Hat)
- Packaging a Python Wheel as RPM by Marco Antonio Carcano