Skip to content

Instantly share code, notes, and snippets.

@lboulard
Last active December 7, 2023 19:11
Show Gist options
  • Save lboulard/0c74f70476cb8173a966c78afab2ae7e to your computer and use it in GitHub Desktop.
Save lboulard/0c74f70476cb8173a966c78afab2ae7e to your computer and use it in GitHub Desktop.
Silent install of multiple python versions #windows
*.bat eol=crlf
*.xml eol=crlf

Silent installation of Python

Made for multiple installation of python on same machine.

Works and tested with Python 3.5 to 3.8.

Installation

Copy all dosbatch and xml files next to installer named like Python-3.x.y-amd64.exe.

Configure default python for script launch

For default python, as administrator, run unattend-default.bat to create file unattend.xml needed for silent installation.

For all other python installations, as administrator, run unattend-not-default.bat to create file unattend.xml needed for silent installation.

See Caveats if you need to change default python version on already configured computer.

Silent installation

For each python that needs to be installed, run python-silent-install.bat.

Silent uninstallation

For each python that needs to be removed from computer, run python-silent-install.bat.

Full offline installation

Use download-debug.bat to fetch all installation medias including debug files and symbols.

Caveats

Changing a non-default installation to become default installation does not work when minor version is not changed. Installers seems to ignore new settings on existing installation. Issue observed when going from version 3.6 to existing version 3.7.

  • To change default python version from 3.N to 3.N+1:
    • version 3.N must be uninstalled first
    • version 3.N+1 must be uninstalled after
    • change unattend.xml of version 3.N to unattend-not-default.xml
    • change unattend.xml of version 3.N+1 to unattend-default.xml
    • install version 3.N, then version 3.N+1
@SETLOCAL
@CD /D "%~dp0"
@SET PYVER=
@FOR %%f IN ("python-3.*-amd64.exe") DO @SET "PYVER=%%~nf"
@ECHO SET PYVER=%PYVER%
@IF NOT DEFINED PYVER (
ECHO ** ERROR: No Python installation program found
GOTO :EOF
)
".\%PYVER%.exe" /passive /layout "%PYVER%"
@SETLOCAL
@CD /D "%~dp0"
@SET PYVER=
@FOR %%f IN ("python-3.*-amd64.exe") DO @SET "PYVER=%%~nf"
@ECHO SET PYVER=%PYVER%
@IF NOT DEFINED PYVER (
ECHO ** ERROR: No Python installation program found
GOTO :NagUser
)
@IF NOT EXIST "%LOCALAPPDATA%\lboulard" MD "%LOCALAPPDATA%\lboulard"
@IF NOT EXIST "%LOCALAPPDATA%\lboulard\logs" MD "%LOCALAPPDATA%\lboulard\logs"
@
@IF "%1"=="uninstall" GOTO :Uninstall
@IF NOT EXIST "unattend.xml" (
ECHO **ERROR: unattend.xml file is missing
GOTO :NagUser
)
"%PYVER%.exe"^
/passive^
/log "%LOCALAPPDATA%\lboulard\logs\%PYVER%-install.log"
IF ERRORLEVEL 1 GOTO :NagUser
@GOTO :EOF
@:Uninstall
"%PYVER%.exe"^
/uninstall^
/passive^
/log "%LOCALAPPDATA%\lboulard\logs\%PYVER%-uninstall.log"
@IF ERRORLEVEL 1 GOTO :NagUser
@GOTO :EOF
@
@:NagUser
@:: Pause if not interactive
@ECHO %cmdcmdline% | FIND /i "%~0" >NUL
@IF NOT ERRORLEVEL 1 PAUSE
CALL "%~dp0python-silent-install.bat" uninstall
@IF ERRORLEVEL 1 GOTO :NagUser
@GOTO :EOF
@:NagUser
@:: Pause if not interactive
@ECHO %cmdcmdline% | FIND /i "%~0" >NUL
@IF NOT ERRORLEVEL 1 PAUSE
@SETLOCAL
@CD "%~dp0"
@IF EXIST unattend.xml DEL unattend.xml
mklink unattend.xml unattend-defaultpy.xml
@IF NOT ERRORLEVEL 1 GOTO :EOF
@:NagUser
@:: Pause if not interactive
@ECHO %cmdcmdline% | FIND /i "%~0" >NUL
@IF NOT ERRORLEVEL 1 PAUSE
<Options>
<Option Name="InstallAllUsers" Value="yes" />
<Option Name="Include_launcher" Value="1" />
<Option Name="Include_symbols" Value="1" />
<Option Name="SimpleInstall" Value="yes" />
<Option Name="PrependPath" Value="0" />
<Option Name="CompileAll" Value="0" />
<Option Name="Include_launcher" Value="1" />
<Option Name="SimpleInstallDescription">
Default python installation for lboulard
</Option>
<Option Name="AssociateFiles" Value="1" />
</Options>
@SETLOCAL
@CD "%~dp0"
@IF EXIST unattend.xml DEL unattend.xml
mklink unattend.xml unattend-not-defaultpy.xml
@IF NOT ERRORLEVEL 1 GOTO :EOF
@:NagUser
@:: Pause if not interactive
@ECHO %cmdcmdline% | FIND /i "%~0" >NUL
@IF NOT ERRORLEVEL 1 PAUSE
<Options>
<Option Name="InstallAllUsers" Value="yes" />
<Option Name="Include_launcher" Value="1" />
<Option Name="Include_symbols" Value="1" />
<Option Name="SimpleInstall" Value="yes" />
<Option Name="PrependPath" Value="0" />
<Option Name="CompileAll" Value="0" />
<Option Name="Include_launcher" Value="1" />
<Option Name="SimpleInstallDescription">
Default python installation for lboulard
</Option>
<Option Name="AssociateFiles" Value="0" />
</Options>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment