Multiple versions of Python coexisting in the same OS

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sun Jul 25 20:41:25 EDT 2010


On Sun, 25 Jul 2010 15:19:53 -0400, Edward Diener wrote:

> On 7/25/2010 10:03 AM, Thomas Jollans wrote:
>> On 07/25/2010 02:46 PM, Edward Diener wrote:
>>> The problem with this is that you forget that a script can invoke
>>> Python internally. So whether one uses the console or file association
>>> method of invoking Python externally, any already written script can
>>> use either internally.
>>
>> Maybe it's just me, but I think that a script that does this is quite
>> simply badly written: it *will* break on systems that have multiple
>> Python versions.
> 
> Whether it is badly written or not in your opinion it is legal and
> happens all the time.

Yes, people write poorly written, buggy scripts all the time. Just 
because code is legal syntax doesn't mean it does what is intended, or 
that what is intended is sensible.

If you have multiple versions of Python installed, and you call "python 
somescript.py" without knowing *which* Python will be called, it is 
neither sensible nor does it do what you intend. End of story.

This is no different from calling any other application without knowing 
what version you will get, then relying on features that are only 
available in some versions. It is just buggy code.


> Are you going to refuse to use any script, no
> matter for what library or for what purpose, that internally invokes
> Python either through a 'python' command or through a file with a Python
> extension ? And how would you find out if a script did this or not ? Are
> going to search every script in every distribution and library to
> determine if it does this ? And when you find out a script does this,
> what will you do ?

Treat it like any script with a bug: fix the bug, stop using the script, 
or determine a work-around that masks the bug. All three are acceptable, 
the third being the least acceptable because it just leaves a bug waiting 
to bite you again in the future.


> Be real. saying you do not like scripts that internally invoke Python
> does not solve anything if you have multiple coexisting versions of
> Python installed.

No, it solves it completely. Treat it as a bug, and fix it. 

If you're not willing to treat it as a bug, then uninstall all but one of 
the Python versions, and the problem goes away. You might have a 
different problem, namely that some scripts stop working, but now the 
solution is obvious and straight-forward: fix the scripts that aren't 
working.

Or rename the Python applications, so that scripts can easily call the 
right version without getting confused.

Trying to make some brittle, Do-What-I-Mean solution for trying to auto-
magically select between Python versions is pursuing a path of endless 
problems. Any solution that doesn't fix the actual problem, namely that 
the scripts are buggy, is at best just a work-around and at worst is no 
solution at all.


-- 
Steven



More information about the Python-list mailing list