Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a rpm for python application

Tags:

python

rpm

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:

  • https://docs.python.org/3.5/distutils/builtdist.html
  • http://docs.python-guide.org/en/latest/shipping/packaging/

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.

like image 841
Sam Avatar asked Feb 16 '17 23:02

Sam


People also ask

What is RPM in python?

The rpm-python package contains a module that permits applications written in the Python programming language to use the interface supplied by RPM Package Manager libraries. This package should be installed if you want to develop Python programs that will manipulate RPM packages and databases.

Does python use RPM?

The RPM database and Python Python is a great default language for system administrators, and the RPM database comes with bindings that make it easy to query with Python. [ Sign up for the free online course Red Hat Enterprise Linux Technical Overview. ]


1 Answers

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
like image 149
Gang Avatar answered Oct 26 '22 13:10

Gang