How to create a rpm for python application

Sam picture Sam · Feb 17, 2017 · Viewed 9.1k times · Source

I have a simple application (just one .py file), that is using cherrypy & flask-restful to present a web service. My development environment is Windows. I use Python 3.5.2 and also create and use virtualenv to work on my project.

I have a need to deploy this on Linux systems. I was asked to create a "RPM" for this so that it can be installed and run on Linux machines.

I have googled and read several pieces of documentation:

But I'm very unclear on the steps that needs to be done to deploy this on a Linux system. Thanks in advance for all your help.

Answer

Gang picture Gang · Feb 17, 2017

This is a mini demo structure output by tree command, color_print is the package name and directory

.
├── color_print
│   ├── color_print.py
│   └── __init__.py
├── __init__.py
└── setup.py

Here is an example setup.py for demo

from setuptools import setup

setup(name='color_print',
    version='0.1',
    description='Color String',
    url='http://github/xxxx/color_print/',
    author='Joe Bob',
    author_email='[email protected]',
    license='MIT',
    packages=['color_print'],
    zip_safe=False)

There is no need to change directory, run this one command to build rpms

python setup.py bdist_rpm

Here is the output, it is that easy:

-bash-4.1$ find . -name "*.spec"
./build/bdist.linux-x86_64/rpm/SPECS/color_print.spec
-bash-4.1$ find . -name "*.rpm"
./dist/color_print-0.1-1.noarch.rpm
./dist/color_print-0.1-1.src.rpm

In reality, you will definitely need to modify the spec files manually. and run

rpmbuild -ba ./build/bdist.linux-x86_64/rpm/SPECS/color_print.spec