1 #!/usr/bin/env powershell 2 # Install Python 3.8 for x64 and x86 in order to build wheels on Windows. 3 4 Set-StrictMode -Version 2 5 $ErrorActionPreference = 'Stop' 6 7 # Avoid "Could not create SSL/TLS secure channel" 8 [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 9 Install-Pythonnull10function Install-Python { 11 Param( 12 [string]$PythonVersion, 13 [string]$PythonInstaller, 14 [string]$PythonInstallPath, 15 [string]$PythonInstallerHash 16 ) 17 $PythonInstallerUrl = "https://www.python.org/ftp/python/$PythonVersion/$PythonInstaller.exe" 18 $PythonInstallerPath = "C:\tools\$PythonInstaller.exe" 19 20 # Downloads installer 21 Write-Host "Downloading the Python installer: $PythonInstallerUrl => $PythonInstallerPath" 22 Invoke-WebRequest -Uri $PythonInstallerUrl -OutFile $PythonInstallerPath 23 24 # Validates checksum 25 $HashFromDownload = Get-FileHash -Path $PythonInstallerPath -Algorithm MD5 26 if ($HashFromDownload.Hash -ne $PythonInstallerHash) { 27 throw "Invalid Python installer: failed checksum!" 28 } 29 Write-Host "Python installer $PythonInstallerPath validated." 30 31 # Installs Python 32 & $PythonInstallerPath /quiet InstallAllUsers=1 PrependPath=1 Include_test=0 TargetDir=$PythonInstallPath 33 if (-Not $?) { 34 throw "The Python installation exited with error!" 35 } 36 37 # NOTE(lidiz) Even if the install command finishes in the script, that 38 # doesn't mean the Python installation is finished. If using "ps" to check 39 # for running processes, you might see ongoing installers at this point. 40 # So, we needs this "hack" to reliably validate that the Python binary is 41 # functioning properly. 42 43 # Wait for the installer process 44 Wait-Process -Name $PythonInstaller -Timeout 300 45 Write-Host "Installation process exits normally." 46 47 # Validate Python binary 48 $PythonBinary = "$PythonInstallPath\python.exe" 49 & $PythonBinary -c 'print(42)' 50 Write-Host "Python binary works properly." 51 52 # Installs pip 53 & $PythonBinary -m ensurepip --user 54 55 Write-Host "Python $PythonVersion installed by $PythonInstaller at $PythonInstallPath." 56 } 57 58 $Python38x86Config = @{ 59 PythonVersion = "3.8.0" 60 PythonInstaller = "python-3.8.0" 61 PythonInstallPath = "C:\Python38_32bit" 62 PythonInstallerHash = "412a649d36626d33b8ca5593cf18318c" 63 } 64 Install-Python @Python38x86Config 65 66 $Python38x64Config = @{ 67 PythonVersion = "3.8.0" 68 PythonInstaller = "python-3.8.0-amd64" 69 PythonInstallPath = "C:\Python38" 70 PythonInstallerHash = "29ea87f24c32f5e924b7d63f8a08ee8d" 71 } 72 Install-Python @Python38x64Config 73