Skip to content

Commit c5dd068

Browse files
authored
Fix Windows Miniconda3 to Python3.9 latest Miniconda3-py39_22.11.1-1-Windows-x86_64 (#1404)
We need to fix Miniconda3 to 3.9 (latest Miniconda3-py39_22.11.1-1-Windows-x86_64) instead of using Miniconda3-latest-Windows-x86_64. The latter nows use Python3.10 which will causes conflicts when installing conda dependencies. This also makes `python` and `python3` command available when SSM into Windows runners or when PowerShell is used in the CI. ### Testing Windows 2019 GHA CI - 20230117193537 us-east-1: ami-05762847639f4dd95 us-east-2: ami-0ed1deea6abeeed3b pytorch/pytorch-canary#158
1 parent 55f446b commit c5dd068

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

aws/ami/windows/scripts/Installers/Install-Miniconda3.ps1

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ if (-Not (Test-Path -Path $parentDir)) {
1212
New-Item -Path $parentDir -ItemType "directory"
1313
}
1414

15-
$condaFilename = "Miniconda3-latest-Windows-x86_64.exe"
15+
# Miniconda3-latest-Windows-x86_64 nows use Python3.10 which will causes conflicts
16+
# later on when installing
17+
$condaFilename = "Miniconda3-py39_22.11.1-1-Windows-x86_64.exe"
1618
$condaURI = "https://repo.anaconda.com/miniconda/$condaFileName"
1719

1820
Write-Output "Downloading Miniconda from $condaURI to $downloadDir, please wait ..."
@@ -32,3 +34,45 @@ if (-Not (Test-Path -Path $condaHook -PathType Leaf)) {
3234

3335
# Clean up the temp file
3436
Remove-Item -Path "$downloadDir\*" -Recurse -Force -ErrorAction SilentlyContinue
37+
38+
# https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles
39+
$PS_PROFILE = "$PSHOME\Microsoft.PowerShell_profile.ps1"
40+
41+
$PYTHON_PATH = '$Env:PATH += ' + "';$installationDir'"
42+
# Add conda path to the powershell profile to make its commands, i.e. python, available when logging
43+
# in to Windows runners or when the CI uses powershell
44+
Add-Content "$PS_PROFILE" "$PYTHON_PATH"
45+
46+
$Env:PATH += ";$installationDir"
47+
# According to https://docs.conda.io/en/latest/miniconda.html, Miniconda have only one built-in
48+
# python executable, and it can be Python3 or 2 depending on which installation package is used
49+
try {
50+
$PYTHON = (Get-Command python).Source
51+
} catch {
52+
$PYTHON = ""
53+
}
54+
55+
If ("$PYTHON" -eq "") {
56+
Write-Output "Found no Python in $Env:PATH. Double check that Miniconda3 is setup correctly in the AMI"
57+
}
58+
Else {
59+
Write-Output "Found Python command at $PYTHON"
60+
}
61+
62+
try {
63+
$PYTHON3 = (Get-Command python3).Source
64+
} catch {
65+
$PYTHON3 = ""
66+
}
67+
68+
If ("$PYTHON3" -eq "") {
69+
Write-Output "Found no Python 3 in $Env:PATH. This is expected for Miniconda3, and the command will be an alias to Python"
70+
}
71+
Else {
72+
Write-Output "Found Python 3 command at $PYTHON3"
73+
}
74+
75+
If (("$PYTHON3" -eq "") -and ("$PYTHON" -ne "")) {
76+
# Setup an alias from Python3 to Python when only the latter exists in Miniconda3
77+
Add-Content "$PS_PROFILE" "Set-Alias -Name python3 -Value $PYTHON"
78+
}

0 commit comments

Comments
 (0)