Python is a powerful language that allows you to create wide range of applications and even websites. Sometimes you may need to create RPM for python module. Here are the steps to create RPM for python module.
How to Create RPM for Python Module
Here are the steps to create RPM for Python Module.
1. Install Pre-requisites
You need to install a few packages to be able to create an RPM package in CentOS/RHEL/SUSE/Fedora systems. Open terminal and run the following command to install them.
$ yum install rpm-build rpmdevtools
2. Create Directory Structure
We need to create a directory structure with required files, for the purpose of creating RPM files. Here is how our folder looks like. Replace test_pack with the name of your package.
. ├── test_pack │ ├── test_pack.py │ └── __init__.py ├── __init__.py └── setup.py
3. Update setup.py
Open setup.py file in a text editor.
$ sudo vi setup.py
Add the following lines to it. Replace test_pack with the name of your package, author, author email and other parameters as per your requirement.
from setuptools import setup setup(name='test_pack', version='0.1', description='Color String', url='http://github/xxxx/test_pack/', author='John', author_email='john@gmail.com', license='MIT', packages=['test_pack'], zip_safe=False)
Save and close the file.
4. Build RPMs
Run the following command to build RPMs.
$ python setup.py bdist_rpm
You will see the following output.
-bash-4.1$ find . -name "*.spec" ./build/bdist.linux-x86_64/rpm/SPECS/test_pack.spec -bash-4.1$ find . -name "*.rpm" ./dist/test_pack-0.1-1.noarch.rpm ./dist/test_pack-0.1-1.src.rpm
You can install the RPM package with the following command.
$ rpm -ivh ./dist/test_pack-0.1-1.noarch.rpm
If you want, you can modify the SPEC file as per your requirement to customize your package. Open it in text editor and customize it as per your requirement.
$ sudo vi ./build/bdist.linux-x86_64/rpm/SPECS/test_pack.spec
Then run the following command to create RPM packages.
$ rpmbuild -ba ./build/bdist.linux-x86_64/rpm/SPECS/test_pack.spec
On a related note, if you are looking to create RPM file from .deb file, then follow our steps here.
That’s it. In this article, we have learnt how to create RPM files from python script.
Also read:
What is NoReverseMatch Error and How To Fix It
How to Create RPM from Shell Script
How to Enable Email Alerts in Keepalived
How to Use NMAP in Kali Linux
How to Install VirtualBox in Ubuntu
Related posts:
Sreeram has more than 10 years of experience in web development, Python, Linux, SQL and database programming.