Easy installation of older python versions in Gentoo

Sometimes when you are to provide backward compatibility with particular version of somewhat you’d better have at least two versions of it: the oldest and the newest ones.

RBTools have its developers to look back on Python 2.4.  Unfortunately, until recently, I had to manually check backward compatibility of used libraries and language features and sometimes failed to do that forcing reviewers to do extra work and reject my review requests.

The most trivial (but not easiest) solution is to fetch python sources somewhere in $HOME and build it manually:

$>wget http://www.python.org/ftp/python/2.4.6/Python-2.4.6.tar.bz2
$>tar xjf  Python-2.4.6.tar.bz2 && rm Python-2.4.6.tar.bz2
$>cd Python-2.4.6
$>./configure && make

I didn’t mention before that another useful thing for python developers is virtualenv which allows to have separate python environments. So if you already use it you’ll have a problem at this point: virtualenv does not allow to use specified interpreter unless it’s located under /usr/local. So you’ll have to move it at least there. As I’m one of those who tries to maintain their system as clean as possible I started to search another way to solve the problem. And suddenly I recalled that I’m running Gentoo with its complicated (at least for me) notion of package slots. Briefly speaking, slot system allows you to install particular piece of software and protect it from being removed or updated. To install package in a new slot you must providie ‘-1’ or ‘–oneshot’ option for emerge. The only problem remains – how to install some very old version? Easy! Just provide required version separated from the package name with a colon:

$>emerge -1av python:2.4

Ok, now you get it. From this point you just need to run virtualenv with specified python version:

$>virtualenv .ve-2.4 -p python2.4

This is it! It remains to repeat installation of required modules for the new environment. Optionally, I like to link frequently used binaries:

$>ln -s .ve-2.4/bin/python2.4
$>ln -s .ve-2.4/bin/nosetest-2.4

Leave a Reply

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

WordPress.com Logo

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s