[Python-Dev] Adding Python scripts to PATHEXT on Windows

Steve Dower Steve.Dower at microsoft.com
Sun Jul 28 01:30:47 CEST 2013


From: Paul Moore <p.f.moore at gmail.com>
> I'm a bit confused by your comment about "people who prefer to associate scripts
> with an editor", though. This is only done in precisely those situations when
> the installer associates .py scripts with py.exe (the launcher). So if you
> switch that off, you don't get PATHEXT either.

That's optional enough for me - I always disable that (because I typically have 4-10 different versions installed at once).

> And if you change the association after the fact, you're presumably just as capable
> of changing PATHEXT.

Not if the association is changed by another installer (presumably with the user's explicit permission). It would be very easy for people to go a long time without noticing this until some program does ShellExecute(...) on a name that happens to be a Python script and Visual Studio pops open...

>> Env var changes typically require a reboot to take full effect, which I've also seen cause confusion.
> Really? If I add python.exe to PATH in the installer do I need to reboot? (I
> never do this, so I don't know - it's a genuine question).

Env vars are inherited by child processes, so until you create a process without inheriting them, you won't see the new value. Depending on the shortcut used, cmd.exe is likely to inherit the variables from explorer.exe, which won't see the new ones until you log off/on again. Certainly any running prompts will need to be closed and restarted after installing.

That said, on my Win8 machine, cmd.exe seems to be okay after changing the variables. However, PowerShell did not see the change immediately, so cmd.exe may be getting special treatment (or just ignoring the default environment).

>> Also, it should include .pyw, .pyz and whatever was decided instead
>> of .pywz (.pwz, I think?).
>
> It's basically a command line thing - I don't see why you'd want to launch
> a GUI script from the command line in the same way.

That's fair enough, though it may be seen as inconsistent. TBH I've never actually seen anything in the wild other than .py.

My suspicion is that the .exe wrappers would remain for tools like pip anyway, rather than breaking people who choose to deselect that option. Of course, it's easy enough to replace them.

Another issue to consider is that the modification to PATHEXT can't be undone when Python is uninstalled, unless each installation adds another ".PY" and each uninstall removes only one (so my PATHEXT would look like ...;.PY;.PY;.PY;.PY;.PY;.PY;.PY;.PY;.PY;.PY). I haven't checked, but this could seriously hurt performance of anything that uses PATHEXT to search PATH for anything ending in this extension. I hope that cmd.exe and PowerShell check for duplicate extensions, but I wouldn't be betting any money that they do.


Steve




More information about the Python-Dev mailing list