Dealing with python version

Jeff Shannon jeff at ccvcorp.com
Wed Mar 27 14:46:01 EST 2002


Andrei Kulakov wrote:

> Hello,
>
> Correct me if I'm wrong, but it seems like if python1.6 or 2.0 are
> already installed and you install a newer version, python command still
> points to the old interpreter.

Depends on the OS you're using.


> I think it would be sensible to use the newest installed python to run
> a program. Is there some elegant way to do that?

Depends on the OS you're using.


> I would ideally prefer it to run using newest interpreter available
> unless it's older than some minimum requirement. It's not very
> user-friendly to put #!/usr/bin/env python2.1 bang line and then say in
> a README that if user gets an error, he has to somehow find out what's
> the latest version he's got and change the bang line to it.
>
> What's the proper way to deal with all of this?

Depends on the OS you're using.  ;)

Seriously, though... you're obviously using some sort of *nix (this
particular issue isn't a problem on Windows).  In general, on *nix,
/usr/bin/python should be a symbolic link to the version you want to use,
and it wouldn't be difficult to change that to point to the new version.
The problem comes when you're using, say, Red Hat, which has system
utilities that rely on Python 1.5.2 and break under 2.*, so that you
effectively cannot change /usr/bin/python to mean anything other than 1.5.2
(RedHat "solves" this by symlinking 2.* as /usr/bin/python2).  However,
there isn't an easy way to identify which Python version a given script
should be run under.

Typically, the most practical way to deal with this is to use plain
"python" in the shebang line, and then document that your package requires
a certain minimum version.

Jeff Shannon
Technician/Programmer
Credit International





More information about the Python-list mailing list