Last active
August 22, 2022 15:13
-
-
Save illume/aa9236573a4aa1217918861427f0048e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install specified Python version. | |
# Install only if: | |
# Our current matrix entry uses this Python version AND | |
# Python version is not already available. | |
# from https://raw.githubusercontent.com/matthew-brett/multibuild/11a389d78892cf90addac8f69433d5e22bfa422a/install_python.ps1 | |
$py_exe = "${env:PYTHONPATH}\Python.exe" | |
if ( [System.IO.File]::Exists($py_exe) ) { | |
echo "$py_exe exists" | |
exit 0 | |
} | |
$req_nodot = $env:PYTHONPATH -replace '\D+Python(\d+(?:rc\d+)?)(-x64)?','$1' | |
$req_ver = $req_nodot -replace '(\d)(\d+)','$1.$2.0' | |
$req_dir = $req_nodot -replace '(\d)(\d+)(.*)','$1.$2.0' | |
$last_three = $env:PYTHONPATH[-3 .. -1] -join '' | |
if ($last_three -eq "x64") { | |
$exe_suffix="-amd64" | |
} else { | |
$exe_suffix="" | |
} | |
$py_url = "https://www.python.org/ftp/python" | |
Write-Host "Installing Python ${req_dir}/${req_ver}$exe_suffix to $env:PYTHONPATH ..." -ForegroundColor Cyan | |
$exePath = "$env:TEMP\python-${req_ver}${exe_suffix}.exe" | |
$downloadFile = "$py_url/${req_dir}/python-${req_ver}${exe_suffix}.exe" | |
Write-Host "Downloading $downloadFile..." | |
(New-Object Net.WebClient).DownloadFile($downloadFile, $exePath) | |
Write-Host "Installing..." | |
cmd /c start /wait $exePath /quiet TargetDir="$env:PYTHONPATH" Shortcuts=0 Include_launcher=0 InstallLauncherAllUsers=0 | |
Write-Host "Python ${req_ver} installed to $env:PYTHONPATH" | |
echo "$(& $py_exe --version 2> $null)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment