[Tutor] Fw: Wrong version of Python being executed

Tiger12506 keridee at jayco.net
Tue Nov 20 22:19:01 CET 2007


I haven't seen anybody write down the full picture so that we are not
misled. Windows chooses which python to use in this manner.

1) If you double click on a .py file in windows, it looks in the registry
for the command string that pertains to "open".
    The .py extension has a default value that tells which type of file it
is, this 'type' has it's own seperate command for "open"
    (So 'txtfile' will have a different open command than 'mp3file', for
example.)

    If in the command interpreter (sometimes inaccurately called a dos box)
you type the name of the .py file (WITHOUT typing python),
    then windows will open it with whatever value is in the registry, just
as if you had double clicked it in explorer.

2) However, if you type python before the script name, then windows checks
first
     a) in the directory that the prompt is at
     b) checks in each directory in the PATH environment variable for an
executable named python.exe and uses that

I have not found that the PYTHONPATH environment variable has any effect
(which i doubt it would, as windows does not make a
special case to check it before hand, and I doubt that python.exe will check
that environ var and spawn the proper version before it runs the script)
I am absolutely certain that the #! at the beginning of the python file does
NOT work in windows, it is strictly a *nix thing.

There are many solutions to this, my favorite being where one adds an extra
entry to the sub menu of the .py file.
Effectively what happens is that another key and value is added to the
registry, providing an alternate command string for "open"

If you go to control panel->folder options->file associations and choose py
file and click advanced, there should be an option to add
another "verb" i believe they call it. So add one and call it open w/23 or
something to distinguish it from regular "open" and put in the
command box the full path of the python exe, followed by "%1" with quotes,
so that when you choose that menu option it will run
that particular python and send the name of the file through %1 so it is
passed in as the argument. Then, when you want to run it with
your default python, you right-click->open. When you want to run it with the
different version, right-click->open w/23 or whatever you
called it.

hope this helps
JS



More information about the Tutor mailing list