coding for multiple versions of python

Chris Rebert clp2 at
Fri Aug 14 06:29:58 CEST 2009

On Thu, Aug 13, 2009 at 12:57 PM, Tim Arnold<tim.arnold at> wrote:
> Hi,
> I've got a python based system that has to run on hp unix and red hat linux.
> The Python version on the HP is 2.4 and the version on the Linux box is 2.6.
> There's nothing I can do about that.
> I think that means I must have two different libraries since the pyc files
> are not cross-version compatible.

Why would the .pyc-s matter? They're just an optimization, which fall
back to the .py files. It only matters if the .py sourcecode files are
compatible with both versions.

> But for the part of the system I actually code every day, I'd rather not do
> dual maintenance, having two copies of my code for each platform/version.
> I'm guessing I need to configure cvs to copy files to both locations
> whenever I commit. Does that sound right? Is there a better way I'm not
> thinking of?

Put your code's directory in the PYTHONPATH / sys.path of both Python versions.
You will still have to write code that works in both versions though.
Essentially, don't use any new syntax that's not present in the older
version, and you'll have to work around any new/changed functions you


More information about the Python-list mailing list