|
| 1 | +# Sample script to install Miniconda under Windows |
| 2 | +# Authors: Olivier Grisel, Jonathan Helmus and Kyle Kastner, Robert McGibbon |
| 3 | +# License: CC0 1.0 Universal: http://creativecommons.org/publicdomain/zero/1.0/ |
| 4 | + |
| 5 | +$MINICONDA_URL = "http://repo.continuum.io/miniconda/" |
| 6 | + |
| 7 | + |
| 8 | +function DownloadMiniconda ($python_version, $platform_suffix) { |
| 9 | + $webclient = New-Object System.Net.WebClient |
| 10 | + $filename = "Miniconda3-latest-Windows-" + $platform_suffix + ".exe" |
| 11 | + $url = $MINICONDA_URL + $filename |
| 12 | + |
| 13 | + $basedir = $pwd.Path + "\" |
| 14 | + $filepath = $basedir + $filename |
| 15 | + if (Test-Path $filename) { |
| 16 | + Write-Host "Reusing" $filepath |
| 17 | + return $filepath |
| 18 | + } |
| 19 | + |
| 20 | + # Download and retry up to 3 times in case of network transient errors. |
| 21 | + Write-Host "Downloading" $filename "from" $url |
| 22 | + $retry_attempts = 2 |
| 23 | + for($i=0; $i -lt $retry_attempts; $i++){ |
| 24 | + try { |
| 25 | + $webclient.DownloadFile($url, $filepath) |
| 26 | + break |
| 27 | + } |
| 28 | + Catch [Exception]{ |
| 29 | + Start-Sleep 1 |
| 30 | + } |
| 31 | + } |
| 32 | + if (Test-Path $filepath) { |
| 33 | + Write-Host "File saved at" $filepath |
| 34 | + } else { |
| 35 | + # Retry once to get the error message if any at the last try |
| 36 | + $webclient.DownloadFile($url, $filepath) |
| 37 | + } |
| 38 | + return $filepath |
| 39 | +} |
| 40 | + |
| 41 | + |
| 42 | +function InstallMiniconda ($python_version, $architecture, $python_home) { |
| 43 | + Write-Host "Installing Python" $python_version "for" $architecture "bit architecture to" $python_home |
| 44 | + if (Test-Path $python_home) { |
| 45 | + Write-Host $python_home "already exists, skipping." |
| 46 | + return $false |
| 47 | + } |
| 48 | + if ($architecture -match "32") { |
| 49 | + $platform_suffix = "x86" |
| 50 | + } else { |
| 51 | + $platform_suffix = "x86_64" |
| 52 | + } |
| 53 | + |
| 54 | + $filepath = DownloadMiniconda $python_version $platform_suffix |
| 55 | + Write-Host "Installing" $filepath "to" $python_home |
| 56 | + $install_log = $python_home + ".log" |
| 57 | + $args = "/S /D=$python_home" |
| 58 | + Write-Host $filepath $args |
| 59 | + Start-Process -FilePath $filepath -ArgumentList $args -Wait -Passthru |
| 60 | + if (Test-Path $python_home) { |
| 61 | + Write-Host "Python $python_version ($architecture) installation complete" |
| 62 | + } else { |
| 63 | + Write-Host "Failed to install Python in $python_home" |
| 64 | + Get-Content -Path $install_log |
| 65 | + Exit 1 |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | + |
| 70 | +function InstallCondaPackages ($python_home, $spec) { |
| 71 | + $conda_path = $python_home + "\Scripts\conda.exe" |
| 72 | + $args = "install --yes " + $spec |
| 73 | + Write-Host ("conda " + $args) |
| 74 | + Start-Process -FilePath "$conda_path" -ArgumentList $args -Wait -Passthru |
| 75 | +} |
| 76 | + |
| 77 | +function UpdateConda ($python_home) { |
| 78 | + $conda_path = $python_home + "\Scripts\conda.exe" |
| 79 | + Write-Host "Updating conda..." |
| 80 | + $args = "update --yes conda" |
| 81 | + Write-Host $conda_path $args |
| 82 | + Start-Process -FilePath "$conda_path" -ArgumentList $args -Wait -Passthru |
| 83 | +} |
| 84 | + |
| 85 | + |
| 86 | +function main () { |
| 87 | + InstallMiniconda "3.5" $env:PYTHON_ARCH $env:CONDA_ROOT |
| 88 | + UpdateConda $env:CONDA_ROOT |
| 89 | + InstallCondaPackages $env:CONDA_ROOT "conda-build jinja2 anaconda-client" |
| 90 | +} |
| 91 | + |
| 92 | +main |
0 commit comments