Python Distutils and RPMs Targeting /opt

I think I’ve mentioned before that I’ve been writing more Python code lately. Python is very powerful and the modules available for it make lots of things very easy, including networked application programming.

Today, though, I want to share a little tidbit about creating Linux RPMs to distribute Python scripts/modules that install to a root other than /usr. In particular, a customer had a request to install under /opt. I’ll use /opt/riverace for this example.

Like many Python tasks, there’s already an easy way to generate a RPM. The Python distutils are very cool and it’s very easy to take a distutils-using setup and use python to generate the RPM. It’s as easy as:

python setup.py bdist_rpm

There are lots of blogs, doc pages, etc. that explain how to create your setup.py. The thing I couldn’t find, though, is how to get the RPM to install into /opt.

It turned out to be simple. Just add this to your setup.py:

import sys
sys.prefix = /opt/riverace
setup(name='MyStuff',
...

Voila!

Tags:

One Response to “Python Distutils and RPMs Targeting /opt”

  1. Tweets that mention Python Distutils and RPMs Targeting /opt « Steve Huston's Networked Programming Blog -- Topsy.com Says:

    […] This post was mentioned on Twitter by Python UK, Steve Huston. Steve Huston said: Python Distutils and RPMs Targeting /opt http://wp.me/pmWSn-1R […]

Leave a comment