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
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
eryksun added the comment:
I think a custom action can be added to Tools/msi/msisupport.c to send a WM_SETTINGCHANGE "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.
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
Forrest Shields email@example.com added the comment:
As of 3.8.5 the current shell's PATH is outdated after a commandline system-wide
installation. This makes it very difficult to do a scripted install of Python followed by
pip commands, as they will not be found. In
addition to modifying the PATH in the system scope, the PATH should also be modified for
the current process (shell).
Here is the WORKAROUND I created and am currently using:
pip) rebuild the PATH environment variable for the current process from the concatenation of the PATH environment variables from the System and User scopes (this is how Windows builds the PATH) by using this code:
[Environment]::SetEnvironmentVariable('PATH', [Environment]::GetEnvironmentVariable('PATH', 'Machine') + ';' + [Environment]::GetEnvironmentVariable('PATH', 'User'), 'Process')
components: +Installation nosy: +forrestshields2 versions: +Python 3.8
Steve Dower firstname.lastname@example.org added the comment:
Sorry, but we don't have any way to update the current terminal process. We already update the current shell, so if you start a new terminal/Powershell/cmd/etc. instance it should have the updated variable.
The workaround you posted is fine. Directly adding the new install to the current PATH is also okay.
resolution: -> out of date stage: -> resolved status: open -> closed
Eryk Sun email@example.com added the comment:
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.