How to build safe, clean Python 2.5 RPMs for Fedora Core 6

Since FC6 ships with Python 2.4, you’re a bit stuck if you want to play with the new features of Python 2.5. Here’s a quick and easy way to build and install a cleanly-packaged version of Python 2.5 for FC6. First, you must ensure that you have a sufficient development environment available. Fortunately, you can do this in one step. Note: this is the only command you’ll need to run with root privileges until the time comes for you to install the Python RPM that you’ve built.
$ sudo yum install autoconf bzip2-devel db4-devel \
  expat-devel findutils gcc-c++ gdbm-devel glibc-devel gmp-devel \
  libGL-devel libX11-devel libtermcap-devel ncurses-devel \
  openssl-devel pkgconfig readline-devel sqlite-devel tar \
  tix-devel tk-devel zlib-devel 
(That’s one long line of input.) This will trundle along for a few minutes, after which you’ll have all of the bits you need installed. Except for Python itself, that is. Simply grab this, in source RPM form, from your nearest friendly Rawhide repository.
lftp ftp://mirrors.kernel.org/fedora/core/development/source/SRPMS
mget python-2*.src.rpm 
Next, install the Python source RPM into a temporary build directory of your choice. In this example, I’ll use “/tmp/mypy”.
mkdir -p /tmp/mypy/{BUILD,RPMS,SOURCES,SPECS}
rpm --define '_topdir /tmp' -ivh python-2*.src.rpm 
Now you’ll need to go into the SOURCES directory and frob a single file:
cd /tmp/mypy/SOURCES
sed -ie 's/DBLIBVER=4.5/DBLIBVER=4.3/' python-2.5-config.patch 
This tells the bsddb module to link against Berkeley DB 4.3 (the default on FC6), rather than 4.5 (which will presumably ship with Fedora 7). The next step is to build the Python RPM.
cd /tmp/mypy/SPECS
rpmbuild --define '_topdir /tmp/mypy' --define '__python_ver 25' -bb python.spec
This takes just a few minutes on my laptop, so it shouldn’t take long for you, either. Once you’re done, the binary RPMs will be present somewhere under /tmp/mypy/RPMS. On a 32-bit x86 machine, they’ll be in the i386 subdirectory, and on an x86_64 machine, they’ll be in the x86_64 subdirectory. You’ll have to become root to install them:
sudo rpm -ivh /tmp/mypy/RPMS/*/*.rpm 
A nice aspect of this way of building is that the packages it builds should not conflict with the system’s default Python, so you ought not to have any peculiar explosions in one of the many system packages that expect a specific Python version. Your new “python” package will be named “python25″, for example, and the interpreter will be named “python25″, too.
Posted in linux, python
22 comments on “How to build safe, clean Python 2.5 RPMs for Fedora Core 6
  1. Kazuyoshi Furutaka says:

    Thanks for a nice/useful page.
    The _topdir for installation of the .src.rpm should be /tmp/mypy.
    Yours,
    Kazuyoshi

  2. Joe says:

    Thanks for the useful instructions which were quite instructive as well as easy to reproduce.

    Kazuyoshi, glad you caught that typo as well.
    Regards

  3. Steve says:

    Please excuse my ignorance, but in trying to follow these directions with an off-line machine, it appears the libGL-devel package checked for in the first step is really known as mesa-libGL-devel? I am going to forge ahead assuming this to be the case since I found no simple libGL-devel package to work with.

  4. Steve, yes – you’re right. I think yum figures out the right package name for you from the provides tags.

  5. Steve says:

    All worked extremely well, you just saved me many, many hours of effort. Many thanks!

  6. Alfred Fazio says:

    Within my configuration, I also had to set the environment variable QA_RPATHS when executing rpmbuild so that standard and empty paths would be ignored (needed by the check-rpaths command). Therefore, the full rpmbuild command became:

    QA_RPATHS=$[ 0x0001|0x0010 ] rpmbuild –define ‘_topdir /tmp/mypy’ –define ‘__python_ver 25′ -bb python.spec

    I’m not sure why I had to do this where others did not… perhaps because of existing modules I had installed?

    Thank you very much for the helpful article!

  7. eXpressColo says:

    These directions also work for CentOS 5 (since CentOS 5 /RHEL 5 are based off Fedora Core 6).

    Thanks for this awesome write up.

  8. Cleiton Freere says:

    I just buit for CentOS 5 and RHEL 5, it worked perfectly!

    Thanks Bryan, it save me a lot of time (which I don’t have)!

  9. Joe Slone says:

    It worked for me as well on CentOS 5. One thing (obvious in hindsight, but it threw me for a moment) that was omited, you need to have installed rpm-build. Thanks much.

  10. Dave Gavin says:

    Thanks for a great write-up. One problem I found:

    rpm –define ‘_topdir /tmp’ -ivh python-2*.src.rpm

    loaded the SOURCES and SPECS in /tmp, not under /tmp/mypy.
    It worked when I changed the _topdir like this:

    rpm –define ‘_topdir /tmp/mypy’ -ivh python-2*.src.rpm

  11. Gary says:

    Thanks very much – I know this is now an old article, but I had to make a couple of other changes since I had fc9 src rpms.

    I used a different regex in the modding the patch file:

    sed -i ‘s/DBLIBVER=4.[4-9]/DBLIBVER=4.3/’ python-2.5-config.patch

    In the .spec file I needed to change the db4-devel prereq requirement to be >= 4.3.

  12. scott says:

    Looks like the source rpm moved to here on the mirror:

    lftp mirrors.kernel.org:/fedora/development/source/SRPMS
    mget python-2*.src.rpm

  13. scott says:

    ****Note to new users****

    Be careful pasting lines of code from the comments above. The code ” quotes are formatted funky by the site and don’t retain clean ‘ quote as in the original posted code snippets that are properly formated.

    Paste them, but before executing them go in and change the quotes back to quote marks.

    Scott

  14. Jamie Quint says:

    lftp ftp://mirrors.kernel.org/fedora/core/development/source/SRPMS

    you will have to also replace “development” with “6” here

  15. Jamie Quint says:

    actually ignore the above comment :) however that repository was not working for me, development was not showing up. Found the applicable file here: http://ftp.cse.yzu.edu.tw/pub/Linux/Fedora/core/development/source/SRPMS/python-2.5-12.fc7.src.rpm

  16. Amy says:

    Anyone else run into this when trying to build on cent5.1?

    gcc -pthread -shared Modules/_bsddb.o -L/usr/lib -ldb-4.5 -o Modules/_bsddb.so
    /usr/bin/ld: cannot find -ldb-4.5
    collect2: ld returned 1 exit status
    make: *** [Modules/_bsddb.so] Error 1
    error: Bad exit status from /var/tmp/rpm-tmp.33492 (%build)

  17. KiwiFrog says:

    Anyone getting the following error when building the rpm?

    [root@xxxx SPECS]# rpmbuild –define ‘_topdir /tmp/mypy’ –define ‘__python_ver 25′ -bb python.spec
    error: Failed build dependencies:
    readline-devel is needed by python25-2.5-12.i386
    openssl-devel is needed by python25-2.5-12.i386
    gmp-devel is needed by python25-2.5-12.i386
    ncurses-devel is needed by python25-2.5-12.i386
    gdbm-devel is needed by python25-2.5-12.i386
    zlib-devel is needed by python25-2.5-12.i386
    expat-devel is needed by python25-2.5-12.i386
    libGL-devel is needed by python25-2.5-12.i386
    tk is needed by python25-2.5-12.i386
    tix is needed by python25-2.5-12.i386
    libX11-devel is needed by python25-2.5-12.i386
    pkgconfig is needed by python25-2.5-12.i386
    tcl-devel is needed by python25-2.5-12.i386
    tk-devel is needed by python25-2.5-12.i386
    tix-devel is needed by python25-2.5-12.i386
    bzip2-devel is needed by python25-2.5-12.i386
    sqlite-devel is needed by python25-2.5-12.i386
    autoconf is needed by python25-2.5-12.i386
    db4-devel >= 4.3 is needed by python25-2.5-12.i386
    tcl is needed by python25-2.5-12.i386

    Any help would be greatly appreciated.
    Thanks.

  18. KiwiFrog says:

    Please ignore the above question. It was my newbie moment ;-).

    BTW, Thanks to the author of this post and all the contributors in the comments.

  19. Rubens Fredrick says:

    i got thru well till i used rpmbuild and got this error.

    wht cud b wrong? m using Centos 5.2

    error: Failed build dependencies:
    db4-devel >= 4.7 is needed by python25-2.5.2-1.x86_64

  20. First off, thank you for a very useful page — it saved me a lot of trouble :-)

    And now some comments:
    1) The sed command line does not work in that it does not edit the file as expected. I just edited it by hand (I know, I was lazy — I should have fixed the sed command line instead)
    2) The .spec file has to be edited as well, for the same reason: “BuildRequires: db4-devel >= 4.3″ instead of “4.6”.
    3) The Fedora packaging team deserves a honorable mention for implementing the nice __python_ver logic inside the spec file 😉

    Hope this helps,
    @Dexter

  21. Fernando Mansito says:

    To Mr. Bryan O’Sullivan

    Dear Mr. Sullivan,

    Thank you very much for your article on building Python 2.5 on Red Hat 5. I have a CentOS 5.4 distro on a friend’s computer and he needs the “Escritorio Movistar” that in turn needs the former.

    On applying your second paragraph i.e. importing all Phython 2* sources from Fedora, I have found that the sources are there no more and get from ftp an error 540 i. e. failed change of directories.

    Would you please still be so kind as to either point me to or send me your own downloaded collection that you used to build Python 2.5 – unless, in your judgement, there is another means to find the sources anywhere else or access the fedora repository elsewhere for them?

    Thank you very much again and best regards,
    fernando mansito

  22. Fernando Mansito says:

    (May I add that at mirrors.kernel.org:/fedora/development/source/SRPMS – see Mr. Scott – what there is now, April 3, 2010, is one only Python source for fc14, not fc6 which you clearly warned is the base for CentOS 5 and therefore, the one that would have to be supposed to work, I’m so sorry).

1 Pings/Trackbacks for "How to build safe, clean Python 2.5 RPMs for Fedora Core 6"
  1. […] going to follow the method detailed in a blog post by Bryan O’Sullivan and build an RPM using a source RPM from the Fedora Project. My system is a 64-bit virtual machine […]

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>