duelling pythons
Geoff Gerrietts
geoff at gerrietts.net
Mon Apr 1 15:56:04 EST 2002
Quoting Gil (gjlap at yahoo.com):
> I think my original install of Python1.5 with RedHat 7.1 is not
> playing nice with a later install of Python2.2. How do I troubleshoot
> this?
Having done this myself a few times, I can give you some pieces of
advice.
By default, if you're compiling python, you're going to install
/usr/local/bin/python. You can take special measures to do otherwise,
but by default, that's where it ends up.
This puts you in the circumstance of having /usr/local/bin/python and
/usr/bin/python, with /usr/local/lib/python2.2 and /usr/lib/python1.5
supporting these two installs.
You may or may not also have /usr/lib/python2.1 and /usr/bin/python2.
Confirm this. Fire them up, one at a time:
/usr/bin/python
/usr/local/bin/python
Verify that the versions are stated correctly.
Have a look at what else you have installed:
/usr/bin/python*
/usr/local/bin/python*
Most of these are just links to one of the core executables, but some
might be different. My RedHat 7.2 system has Python 1.5, Python 2.1,
and Python 2.2 simultaneously installed. I generally don't use
python2.1, but it does exist (which makes cross-version testing
easier).
Lots of RedHat's software relies on the contents of
/usr/lib/python1.5, which is why it sucks to use RedHat for coding
python these days. (On the other hand, they've got lots of extension
modules for 1.5 pre-installed, which is why it's kinda cool to use
RedHat for coding python these days.)
Because RedHat's software relies on the 1.5.2 binary, there's gonna be
some pain if you want to use 2.2. How you take that pain is up to you.
There are two basic options:
DO REDHAT'S DEPENDENCY MANAGEMENT FOR THEM
The first solution is to just use "python2" whenever you want to
use the new features or write forward-portable code. To accomplish
this:
- Make sure that /usr/bin/python1.5 points to the 1.5.2 binary.
- Make sure that /usr/bin/python points to the version you want to
use.
- Make sure that all RedHat's scripts are fixed to point to
python1.5.
It's the last step that's pretty troublesome. You'll need to go
look at /usr/share. There's a lot in this subdirectory, and a
striking percentage of it uses python. You might try "grep -rl
python ." to extract a list of all the files who look at python.
Not all of these need to be changed, but it's hard to pick out
which do and which don't without knowing how the individual
systems involed operate.
Then check /usr/bin and /usr/sbin the same way -- I think there
are some shell scripts in those directories that invoke python.
This is the way RedHat should have shipped the system, if they
were going to be depending on an old version of the python
interpreter, but they didn't.
SUCK IT UP
The second solution is to make all your scripts and all your
installs of recent tools use python2 instead of python. For
anything that uses distutils, I've found this option works pretty
well -- you call "python2 setup.py" and the package configures
itself and builds itself appropriately.
This can be a little more troublesome with packages or scripts
that assume /usr/bin/python will be the one you want, or scripts
that assume /usr/bin/env python will work properly.
This is a hassle, but it's an ongoing hassle that is unlikely to
consume more than 30 mins of work in a sitting, whereas the
previous task is likely to take many, many hours in up-front time.
There's also one other option, but I'm not sure how feasible it is. It
might be the preferred solution, if you can manage it. It might not be
possible, though.
DO REDHAT'S SYSTEM UPDATING FOR THEM
This path, entirely hypothetical at this point, would involve
downloading and building all the extension modules presently
included in /usr/lib/python1.5 for your new version of the
interpreter.
It may also involve debugging some of the old scripts for the new
environment -- a lot has changed between 1.5.2 and 2.2 that could
have backwards-compatibility ramifications for the scripts. But it
may not.
In some ways, this is the ideal approach, but I don't know how
feasible it is.
It's funny that RedHat is such a big believer in Python that they've
written huge swaths of their distribution-management system in python,
yet at the same time they've made it very challenging for Python
programmers to use their distribution. There's something of an
inconsistency there. :)
Good luck,
--G.
--
Geoff Gerrietts <geoff at gerrietts dot net> http://www.gerrietts.net/
"Politics, as a practice, whatever its professions, has always been the
systematic organization of hatreds." --Henry Adams
More information about the Python-list
mailing list