python 2.7 windows silent installer (.msi) - command-line option to set the path?
Solution 1
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/
Solution 2
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.
denfromufa
Currently High-Performance Machine Learning Research at Total. Python, data science, machine learning, deep learning, high-performance computing, numerical simulations, optimization, operations research, software development. Former core developer for pythonnet. Former Faculty of ML @ NAU. Former Google GDE in Machine Learning.
Updated on June 17, 2022Comments
-
denfromufa almost 2 years
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.