This repository has been archived by the owner on Oct 31, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall-miniconda.ps1
160 lines (128 loc) · 4.49 KB
/
install-miniconda.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# Script to set up Miniconda with a test environment
# This script has been heavily adapted from a script by Olivier Grisel and Kyle
# Kastner licensed under a BSD 3-clause license, and subsequently modified by
# Stuart Mumford before being adapted to its current form in ci-helper.
# We use the following function to exit the script after any failing command
function checkLastExitCode {
if ($lastExitCode) {
echo "ERROR: the last command returned the following exit code: $lastExitCode"
Exit $lastExitCode
}
}
$QUIET = "-q"
if ($env:DEBUG) {
if($env:DEBUG -match "True") {
# Show all commands
Set-PSDebug -Trace 1
# Print out environment variables
Get-ChildItem Env:
# Disable Quiet mode
$QUIET = ""
}
}
$MINICONDA_URL = "https://repo.continuum.io/miniconda/"
$env:USED_NUMPY_VERSION = "1.13"
$env:PYTHON_VERSION = 2.7
if (! $env:PIP_FALLBACK) {
$env:PIP_FALLBACK = "True"
}
function DownloadMiniconda ($version, $platform_suffix) {
$webclient = New-Object System.Net.WebClient
$filename = "Miniconda3-" + $version + "-Windows-" + $platform_suffix + ".exe"
$url = $MINICONDA_URL + $filename
$basedir = $pwd.Path + "\"
$filepath = $basedir + $filename
if (Test-Path $filename) {
Write-Host "Reusing" $filepath
return $filepath
}
# Download and retry up to 3 times in case of network transient errors.
Write-Host "Downloading" $filename "from" $url
$retry_attempts = 2
for($i=0; $i -lt $retry_attempts; $i++){
try {
$webclient.DownloadFile($url, $filepath)
break
}
Catch [Exception]{
Start-Sleep 1
}
}
if (Test-Path $filepath) {
Write-Host "File saved at" $filepath
} else {
# Retry once to get the error message if any at the last try
$webclient.DownloadFile($url, $filepath)
}
return $filepath
}
function InstallMiniconda ($miniconda_version, $architecture, $python_home) {
Write-Host "Installing miniconda" $miniconda_version "for" $architecture "bit architecture to" $python_home
if (Test-Path $python_home) {
Write-Host $python_home "already exists, skipping."
return $false
}
if ($architecture -eq "x86") {
$platform_suffix = "x86"
} else {
$platform_suffix = "x86_64"
}
$filepath = DownloadMiniconda $miniconda_version $platform_suffix
Write-Host "Installing" $filepath "to" $python_home
$args = "/S /AddToPath=1 /RegisterPython=1 /D=" + $python_home
Write-Host $filepath $args
Start-Process -FilePath $filepath -ArgumentList $args -Wait -Passthru
#Start-Sleep -s 15
if (Test-Path $python_home) {
Write-Host "Miniconda $miniconda_version ($architecture) installation complete"
} else {
Write-Host "Failed to install Python in $python_home"
Exit 1
}
}
# Install miniconda, if no version is given use the latest
if (! $env:MINICONDA_VERSION) {
$env:MINICONDA_VERSION="latest"
}
# Install miniconda for Windows x64, if no environment is given
if (! $env:PLATFORM) {
$env:PLATFORM="x86_64"
}
# Install no python path is specified
if (! $env:PYTHON) {
$env:PYTHON= $pwd.Path + "\" + "Python"
}
InstallMiniconda $env:MINICONDA_VERSION $env:PLATFORM $env:PYTHON
checkLastExitCode
# Set environment variables
$env:PATH = "${env:PYTHON};${env:PYTHON}\Scripts;" + $env:PATH
# Conda config
conda config --set always_yes true
checkLastExitCode
conda config --add channels anaconda
checkLastExitCode
if ($env:CONDA_CHANNELS) {
$CONDA_CHANNELS=$env:CONDA_CHANNELS.split(" ")
foreach ($CONDA_CHANNEL in $CONDA_CHANNELS) {
conda config --add channels $CONDA_CHANNEL
checkLastExitCode
}
Remove-Variable CONDA_CHANNELS
rm env:CONDA_CHANNELS
}
# Create a conda environment
conda create $QUIET -n test python=$env:PYTHON_VERSION
checkLastExitCode
activate test
checkLastExitCode
# Set environment variables for environment (activate test doesn't seem to do the trick)
$env:PATH = "${env:PYTHON}\envs\test;${env:PYTHON}\envs\test\Scripts;${env:PYTHON}\envs\test\Library\bin;" + $env:PATH
# Check that we have the expected version of Python
# python --version # Don't output, because it prints this thing to the std-error output
pip --version
conda install $QUIET -n test pytest pip numpy scipy matplotlib pytest h5py scikit-image
checkLastExitCode
python -m pip install --upgrade pip wheel setuptools
pip --version
pip install -r requirements.txt
pip install -r requirements_windows.txt