Building RPM of Python Package

Delivering an application is a crucial part and  it becomes essential that the application should support easy and standard way of handling install/upgrade/downgrade/uninstall/reinstall of software.

RPM format is widely used in Linux distribution to install and manage software packages. Linux distribution is also provides YUM Server feature, a way to install packages by resolving dependencies automatically.

In this post, I'll explain about building RPM of Python package and will use SQLAlchmey Package in examples to explain the approaches.

Native Approach:


  1. Download the Python Package that you would like to create RPM of,  from Python Package Index: https://pypi.python.org/pypi  (or) if you have one, developed by yourself using python setuptools, use him
  2. As stated above, this example uses SQLAlchemy Package, downloaded using this link: URL
  3. Python package bundle usually available in zip/tar.gz formats
  4. Extract the package and change current directory to the package directory
  5. Execute # python setup.py bdist_rpm
  6. RPM build process starts and once it completes, by default the RPM files will be available  in dist directory

Note:

  • There are few minor issues in the approach described above, due to the fact that the Python Package developers are more keen on testing the package binary build as it is widely used and more often not concentrated on the binary RPM build. 
  • Because of that, some packages throw error while trying to build them as RPM using setup.py bdist_rpm command. 
  • We will discuss about the common build errors along with ways to fix the errors to build a RPM successful in a different post.

Alternate Approach:

There are several python packages available that provides more convenient way to build RPM file. One such Python package is pypi2rpm
  1. Download pypi2rpm package from Python Package Index: https://pypi.python.org/pypi (or) if your system connected to internet, you may perform the installation through pip CLI by executing the following command # pip install pypi2rpm
  2. Once the installation is completed. Your system will be provided with pypi2rpm.py CLI to build RPM of python package.
  3. Execute pypi2rpm.py CLI following by the python package that you would like to build RPM of, pypi2rpm builds RPM file and the same will be available in the current working directory.
  4. The command to build RPM is as follows,  # pypi2rpm.py SQLAlchemy-1.0.11.tar.gz

Post a Comment

3 Comments