maintain 2 versions of python on my computer

Gertjan Klein gklein at xs4all.nl
Sat Jan 16 03:16:14 EST 2010


Gabriel Genellina wrote:

>En Thu, 14 Jan 2010 08:21:28 -0300, luis <solisgb at gmail.com> escribió:
>
>> Is there any way to indicate the version of the python interpreter
>> must use a script?
>
>See http://www.effbot.org/zone/exemaker.htm
>It uses the #! line to determine which version to load, resembling the  
>Unix way.
>(I've written a variant of the same idea but isn't ready yet)

I'd be interested to see what you've come up with, if you care to share.
I've been thinking about something like this as well. Exemaker, for me,
is the wrong solution, because it requires making an .exe file for every
script you want to run this way.

What I've been thinking about is to write a single executable that gets
associated with .py and .pyw (instead of python.exe itself). This
executable would parse the #! line to look for a specific python
version, or use a configured default if none found (or a parsing error
occurs). It would then invoke the appropriate python version (with
whatever arguments, if any, are supplied).

As far as I can see, this allows both typing the script name and
arguments (i.e., without python31 before it) from a command prompt, and
doubleclicking on a .py or .pyw file from windows explorer. In both
cases, the proper python executable would be used to run the script.

What's been holding me back so far is that probably needs to be written
in C, to prevent the Python runtime's startup overhead. I haven't
written any significant amount of C code in years, if not decades, so
that seems like a daunting task to me at the moment. ;-)

Gertjan.




More information about the Python-list mailing list