[issue24757] Installing Py on Windows: Need to restart or logout for path to be added
New submission from John Palermo:
Something I suppose many new users could stumble over: After installing Python and trying out "pip" or "python" on the command line nothing is found. You have to re-start Windows or re-log into your account.
I suggest adding this information to the documentation here
https://docs.python.org/2/using/windows.html#installing-python
and also adding it to the Windows installer description for the "add Python to your path" option.
----------
assignee: docs@python
components: Documentation
messages: 247688
nosy: John Palermo, docs@python
priority: normal
severity: normal
status: open
title: Installing Py on Windows: Need to restart or logout for path to be added
type: enhancement
versions: Python 2.7
_______________________________________
Python tracker
eryksun added the comment:
I think a custom action can be added to Tools/msi/msisupport.c to send a [WM_SETTINGCHANGE][1] "Environment" message to top-level windows. This makes Explorer reload its environment from the registry, so starting a new command prompt (cmd.exe) from Explorer will see the updated PATH.
[1]: https://msdn.microsoft.com/en-us/library/ms725497
----------
nosy: +eryksun
_______________________________________
Python tracker
Changes by Ned Deily
Steve Dower added the comment:
That's exactly what is needed (though it still won't affect command prompts that are already open).
The 3.5+ installer does it, so this only affects 2.7 and 3.4.
----------
versions: +Python 3.4
_______________________________________
Python tracker
Forrest Shields
Steve Dower
Eryk Sun
We already update the current shell, so if you start a new terminal/Powershell/cmd/etc. instance it should have the updated variable.
The installer broadcasts an "Environment" message to top-level windows. In practice, only Explorer listens for and reloads its environment for this window message. For most programs, a new instance has to be run from Explorer in order to get the updated environment.
CMD and PowerShell don't own any windows, so they cannot get this message in principle. The console-session host process (conhost or openconsole) may own a top-level window if it wasn't allocated with CREATE_NO_WINDOW and wasn't created as a ConPTY server (e.g. under Windows Terminal). But the console doesn't have a console control event for this case (e.g. something like a hypothetical CTRL_ENVIRONMENT_EVENT) that it sends to client processes. It's assumed that console applications that need to interact with the desktop environment will create at least a hidden window.
Without the "Environment" message, it's still possible for the user to run a script that reloads the environment in place in CMD or PowerShell. The environment has to be loaded in four passes: system REG_SZ values, system REG_EXPAND_SZ values, user REG_SZ values, and user REG_EXPAND_SZ values. User values should always be able to depend on system values, and REG_EXPAND_SZ values should always be able to depend on REG_SZ values. This is the way WinAPI CreateEnvironmentBlock has always worked. When reloading PATH, this is an issue if a new machine PATH value depends on new/modified REG_SZ system variables or if a new user PATH value depends on new/modified system variables or new/modified REG_SZ user variables.
----------
_______________________________________
Python tracker
participants (6)
-
Eryk Sun
-
eryksun
-
Forrest Shields
-
John Palermo
-
Ned Deily
-
Steve Dower