@@ -8,92 +8,12 @@ $GET_PIP_URL = "https://bootstrap.pypa.io/get-pip.py"
88$GET_PIP_PATH = " C:\get-pip.py"
99
1010
11- function DownloadPython ($python_version , $platform_suffix ) {
12- $webclient = New-Object System.Net.WebClient
13- $filename = " python-" + $python_version + $platform_suffix + " .msi"
14- $url = $BASE_URL + $python_version + " /" + $filename
15-
16- $basedir = $pwd.Path + " \"
17- $filepath = $basedir + $filename
18- if (Test-Path $filename ) {
19- Write-Host " Reusing" $filepath
20- return $filepath
21- }
22-
23- # Download and retry up to 3 times in case of network transient errors.
24- Write-Host " Downloading" $filename " from" $url
25- $retry_attempts = 2
26- for ($i = 0 ; $i -lt $retry_attempts ; $i ++ ){
27- try {
28- $webclient.DownloadFile ($url , $filepath )
29- break
30- }
31- Catch [Exception ]{
32- Start-Sleep 1
33- }
34- }
35- if (Test-Path $filepath ) {
36- Write-Host " File saved at" $filepath
37- } else {
38- # Retry once to get the error message if any at the last try
39- $webclient.DownloadFile ($url , $filepath )
40- }
41- return $filepath
42- }
43-
44-
45- function InstallPython ($python_version , $architecture , $python_home ) {
46- Write-Host " Installing Python" $python_version " for" $architecture " bit architecture to" $python_home
47- if (Test-Path $python_home ) {
48- Write-Host $python_home " already exists, skipping."
49- return $false
50- }
51- if ($architecture -eq " 32" ) {
52- $platform_suffix = " "
53- } else {
54- $platform_suffix = " .amd64"
55- }
56- $msipath = DownloadPython $python_version $platform_suffix
57- Write-Host " Installing" $msipath " to" $python_home
58- $install_log = $python_home + " .log"
59- $install_args = " /qn /log $install_log /i $msipath TARGETDIR=$python_home "
60- $uninstall_args = " /qn /x $msipath "
61- RunCommand " msiexec.exe" $install_args
62- if (-not (Test-Path $python_home )) {
63- Write-Host " Python seems to be installed else-where, reinstalling."
64- RunCommand " msiexec.exe" $uninstall_args
65- RunCommand " msiexec.exe" $install_args
66- }
67- if (Test-Path $python_home ) {
68- Write-Host " Python $python_version ($architecture ) installation complete"
69- } else {
70- Write-Host " Failed to install Python in $python_home "
71- Get-Content - Path $install_log
72- Exit 1
73- }
74- }
75-
7611function RunCommand ($command , $command_args ) {
7712 Write-Host $command $command_args
7813 Start-Process - FilePath $command - ArgumentList $command_args - Wait - Passthru
7914}
8015
8116
82- function InstallPip ($python_home ) {
83- $pip_path = $python_home + " \Scripts\pip.exe"
84- $python_path = $python_home + " \python.exe"
85- if (-not (Test-Path $pip_path )) {
86- Write-Host " Installing pip..."
87- $webclient = New-Object System.Net.WebClient
88- $webclient.DownloadFile ($GET_PIP_URL , $GET_PIP_PATH )
89- Write-Host " Executing:" $python_path $GET_PIP_PATH
90- Start-Process - FilePath " $python_path " - ArgumentList " $GET_PIP_PATH " - Wait - Passthru
91- } else {
92- Write-Host " pip already installed."
93- }
94- }
95-
96-
9717function DownloadMiniconda ($python_version , $platform_suffix ) {
9818 $webclient = New-Object System.Net.WebClient
9919 if ($python_version -eq " 3.4" ) {
@@ -159,60 +79,8 @@ function InstallMiniconda ($python_version, $architecture, $python_home) {
15979}
16080
16181
162- function InstallMinicondaPip ($python_home ) {
163- $pip_path = $python_home + " \Scripts\pip.exe"
164- $conda_path = $python_home + " \Scripts\conda.exe"
165- if (-not (Test-Path $pip_path )) {
166- Write-Host " Installing pip..."
167- $args = " install --yes pip"
168- Write-Host $conda_path $args
169- Start-Process - FilePath " $conda_path " - ArgumentList $args - Wait - Passthru
170- } else {
171- Write-Host " pip already installed."
172- }
173- }
174-
175-
176- function InstallMinicondaNumpy ($python_home ) {
177- $conda_path = $python_home + " \Scripts\conda.exe"
178- Write-Host " Installing numpy..."
179- # Current WxPython will not work with numpy>1.9.0 due to this bug:
180- # http://trac.wxwidgets.org/ticket/16590
181- # $args = "install --yes numpy"
182- $args = " install --yes 'numpy<1.9.0'"
183- Write-Host $conda_path $args
184- Start-Process - FilePath " $conda_path " - ArgumentList $args - Wait - Passthru
185- }
186-
187- function InstallMinicondaScipy ($python_home ) {
188- $conda_path = $python_home + " \Scripts\conda.exe"
189- Write-Host " Installing scipy..."
190- # Current WxPython will not work with numpy>1.9.0 due to this bug:
191- # http://trac.wxwidgets.org/ticket/16590
192- # $args = "install --yes scipy"
193- $args = " install --yes scipy numpy=1.8"
194- Write-Host $conda_path $args
195- Start-Process - FilePath " $conda_path " - ArgumentList $args - Wait - Passthru
196- }
197-
198-
199- function InstallMinicondaWxpython ($python_home ) {
200- $conda_path = $python_home + " \Scripts\conda.exe"
201- Write-Host " Installing wxpython..."
202- $args = " install --yes wxpython"
203- Write-Host $conda_path $args
204- Start-Process - FilePath " $conda_path " - ArgumentList $args - Wait - Passthru
205- }
206-
207-
20882function main () {
209- # InstallPython $env:PYTHON_VERSION $env:PYTHON_ARCH $env:PYTHON
210- # InstallPip $env:PYTHON
21183 InstallMiniconda $env: PYTHON_VERSION $env: PYTHON_ARCH $env: PYTHON
212- InstallMinicondaPip $env: PYTHON
213- InstallMinicondaNumpy $env: PYTHON
214- InstallMinicondaScipy $env: PYTHON
215- InstallMinicondaWxpython $env: PYTHON
21684}
21785
21886main
0 commit comments