10

When installing python 2.7 on Windows using silent installer (.msi), is there a command-line option to add Python to path environment variable, like the GUI option?

Python 3.5 installer includes an option PrependPath=0 by default, but can Python 2.7 use it?

https://docs.python.org/3/using/windows.html

Looks like this issue was discussed here, but no resolution for Python 2.7?

https://bugs.python.org/issue3561

EDIT


this batch command rocks!!!

setx \M PATH "%PATH%;C:\Python\Python27;C:\Python\Python27\Scripts"

but setx will truncate the stored %PATH% string to 1024 bytes.

5
  • 1
    afaik you can set it through the registry .... if thats helpful ... Commented Dec 11, 2015 at 1:18
  • msi installer should add python to windows registry by default, but adding to path env. var. is different. Commented Dec 11, 2015 at 1:19
  • 1
    no i mean the PATH can be modified through the windows registry Commented Dec 11, 2015 at 1:39
  • 1
    see stackoverflow.com/a/8358361/541038 Commented Dec 11, 2015 at 1:42
  • @JoranBeasley add your answer, I'm going to accept it! Commented Dec 11, 2015 at 1:54

2 Answers 2

14

The Python MSI installer can update the system path since 2.4. Just add ADDLOCAL=ALL to the command line. You'll have to restart your system before it propagates.

msiexec /i "python-2.7.11.amd64.msi" /passive /norestart ADDLOCAL=ALL 

https://www.python.org/download/releases/2.4/msi/

Sign up to request clarification or add additional context in comments.

6 Comments

"You'll have to restart your system before it propagates." - this is not an option in my case.
Perhaps the author meant "restart prompt" instead of system. Running msiexec as above with ADDLOCAL=ALL successfully introduces python to PATH in your next cmd session.
Yes, Chris, I meant system restart. This option updates the registry but it does not force Windows Explorer/Shell to reload the new path value. There's a way to do that, but apparently the Python installer doesn't use it. So, if you launch a program from Explorer after running the installation, the new process inherits the old path, not the registry path. I haven't tested this in ~8 months. Maybe it's changed.
I just tested this on Windows XP (I know) and can confirm an entire restart was required after using ADDLOCAL=ALL with the Python 3.4 MSI installer.
Is restart needed also for 3.5.exe Installer? If i start Installer manually there is no need of restart. :/ I am dealing with this problem here: stackoverflow.com/questions/47310884/…
|
3

I have observed that on Windows 7 (Professional) with python 2.7.14 x64, no restart is required for Python to be added to PATH. Just start up a new command window after the install and python will be in the PATH.

You can determine whether or not a restart is required by the install by running the msi as follows:

start/wait "" msiexec /i "python-2.7.11.amd64.msi" /passive /norestart ADDLOCAL=ALL if %errorlevel% == 3010 ( echo Success: reboot required ) else (if %errorlevel% == 0 ( echo Success ) else ( echo Installation failed with error code %errorlevel% ) ) 

That is, if %errorlevel% is 3010 (ERROR_SUCCESS_REBOOT_REQUIRED), then a reboot will be required. The use of start/wait causes cmd.exe to wait until the msiexec process finishes. This allows the msiexec return status to be available to cmd.exe.

BTW You may wish to include the option ALLUSERS=1 on the command line if you want the installation of Python to be available to all users on the system.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.