Python Setuptools

Python packages can be installed with python setuptools, which uses distutils as the standard library.  To do this generate a file, and then create a specfile just like you normally would.  Normally, the specfile builds c, so to build python it needs to be altered a little bit.  First add the following line to the very start of the specfile.  I had to split into two because it is somewhat long.

%{!?python_sitelib: %define python_sitelib %(%{__python} -c
"from distutils.sysconfig import get_python_lib; print get_python_lib()")}

The rest is the same except for the section where the package is built.  Here is an example of part of one my specfiles.

%setup -q

%{__python} build

%{__python} install -O1 --skip-build --root $RPM_BUILD_ROOT


As you may have noticed the %prep and %clean sections are still the same.  When installing you have to tell distutils it doesn’t need to build, because it already has previously, and specify the root dir.  I managed to figure this out by reverse engineering this pungi specfile.

Previous Home

6 Responses to “Python Setuptools”

  1. Angie Says:

    Amazing tutorial!
    I packaged an RPM for varnish 2.1.1-1. In case you are interested to obtain it, just contact me. You saved me lots of effort and time by this tutorial, thank you so much 🙂

    • kalyan Says:

      Appreciate your document. please help me out with this .
      REQUIREMENT : i have already compiled java class files and jars are created out of it . my purpose is to create rpm which has to have that jar file along with xml files … thats it .. so for this what needs to be done . so in which section do we need to define that . ALso where to give all this things is it in spec file ?

      %setup -q

      %{__python} build

      rm -rf $RPM_BUILD_ROOT
      %{__python} install -O1 –skip-build –root $RPM_BUILD_ROOT

      %cleanrm -rf $RPM_BUILD_ROOT

  2. fred Says:

    Thanks for sharing this. The fungi spec file link is broken: I had to use to have a look at it. Cheers.

  3. Fred Says:

    Thanks for sharing this! The fungi spec file link was broken: I found it at Cheers.

  4. deva Says:

    informative tutorial

  5. Sundar Says:

    Good tutorial. But you have not mentioned about creating rpm after editing spec file. Is there a way to call spec file using inbuilt command “bdist_rpm” or should I have to use “rpmbuild” to generate package? In both the cases an example would have be helpful for new comer like me.

    Nice tutorial though.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: