[Python-Dev] 3.2.1 encoding surprise

Glenn Linderman v+python at g.nevcal.com
Wed Jul 20 11:17:58 CEST 2011


On 7/18/2011 6:41 PM, Vinay Sajip wrote:
>> >      So I can fix my machine, now that I understand what went wrong
>> >       (delete py.exe entries from HCU, and put them in HLM instead).
>> >       Then the other problem I have, is why py.exe launched py 2.6.4
>> >       instead of py 3.2.1 when 3.2.1 is newer, and I don't have a #!
>> >       line.  That is probably the defined behavior of the launcher, to
>> >       prefer 2.x if 3 isn't specified.  I'll have to reread the launcher
>> >       PEP.  In my environment, I would much prefer to use 3.x if 2.x isn't
>> >       specified... so hopefully when I reread the launcher PEP, I'll
>> >       discover a way to do that.  (I recall one can put -3 on the command
>> >       line, so I could do that in the py.exe ftype commands, but hopefully
>> >       there is a way to tweak the py.ini to do that.)
> Yes, the PEP explains what you need to do to get Python 3 to be the default:
> use the py.ini file or use an environment variable.
>
> The use of py from the command line is merely a convenience for developers (as
> the PEP says) - it's better to rely on shebang lines together with settings in
> the .ini to get the behaviour you want.

OK, took a few minutes to play with the launcher again.  I have removed 
the HCU classes that point at the launcher, leaving me with all my 
Python.File stuff pointing at some version of Python or another.  I seem 
to have Python 2.6.4, Python 3.1, and Python 3.2.1 installed, all 64-bit.

py.exe is located in c:\Windows\system32.exe, I modified the empty 
py.ini that was installed to contain

Since I don't yet have associations set up that point at the launcher, I 
thought I'd play with saying "py" in front of the command.

So I have a command foo.py using Python 3 syntax in a directory on my 
PATH.  It works fine, since Python 3.2.1 is in Python.file.  foo.py does 
not have a #! line.

I can successfully execute:  foo.py

However, the following fails:  py foo.py
It fails, because foo.py is not found.  Instead, I have to specify: py 
d:\path\to\foo.py
This is annoying, py should walk the PATH for unqualified files (the 
Windows PATH implicitly includes the current directory, of course, but 
if it were in the current directory, it would just work).

So when I: type c:\windows\system32\py.ini
I get a set of h2 h3 v2 v3 commands in a section called [commands].  Not 
sure where my [defaults] went.  Is there some more Windows magic to be 
explained?  WOW6432-ness, perhaps?  Probably my editor is running as a 
32-bit process, so looked in the wrong C:\windows\system32 !!

OK, with that mystery solved, and using Notepad running as administrator 
to actually, successfully edit the file, it still runs the wrong version 
of Python.  Here is the content of the file, what is wrong?  And why is 
the spacing around the = in the [commands] section so inconsistent?

[defaults]
python=3

[commands]
h2=c:\Python26\python -h
h3 = c:\Python32\python -h
v2= c:\Python26\python -V
v3 =c:\Python32\python -V


OK, so when I specify: py d:\path\to\foo.py
It fails, but this time it is because it launches Python 2.6.4.  So the 
[defaults] section doesn't seem to have an effect.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20110720/a9b88e9d/attachment.html>


More information about the Python-Dev mailing list