install_python.ps1 1.19 KB
Newer Older
1
2
3
4
5
6
7
# Install specified Python version.
# Install only if:
#    Our current matrix entry uses this Python version AND
#    Python version is not already available.

$py_exe = "${env:PYTHON}\Python.exe"
if ( [System.IO.File]::Exists($py_exe) ) {
mattip's avatar
mattip committed
8
    echo "$py_exe exists"
mattip's avatar
mattip committed
9
    exit 0
10
}
mattip's avatar
mattip committed
11
$req_nodot = $env:PYTHON -replace '\D+Python(\d+(?:rc\d+)?)(-x64)?','$1'
12
$req_ver = $req_nodot -replace '(\d)(\d+)','$1.$2.0'
13
$req_dir = $req_nodot -replace '(\d)(\d+)(.*)','$1.$2.0'
mattip's avatar
mattip committed
14
$last_three = $env:PYTHON[-3 .. -1] -join ''
15

mattip's avatar
mattip committed
16
if ($last_three -eq "x64") {
17
18
    $exe_suffix="-amd64"
} else {
mattip's avatar
mattip committed
19
    $exe_suffix=""
20
21
22
}

$py_url = "https://www.python.org/ftp/python"
mattip's avatar
mattip committed
23
Write-Host "Installing Python ${req_dir}/${req_ver}$exe_suffix to $env:Python ..." -ForegroundColor Cyan
24
$exePath = "$env:TEMP\python-${req_ver}${exe_suffix}.exe"
25
$downloadFile = "$py_url/${req_dir}/python-${req_ver}${exe_suffix}.exe"
26

27
28
29
30
31
32
33
Write-Host "Downloading $downloadFile..."
(New-Object Net.WebClient).DownloadFile($downloadFile, $exePath)
Write-Host "Installing..."
cmd /c start /wait $exePath /quiet TargetDir="$env:PYTHON" Shortcuts=0 Include_launcher=0 InstallLauncherAllUsers=0
Write-Host "Python ${req_ver} installed to $env:PYTHON"

echo "$(& $py_exe --version 2> $null)"