install.ps1 3.0 KB

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