install-pyenv-win.ps1
WebClient, archive extraction and launch cluesPowerShell executable name or command options
SHA-25654f9ad87646ee9c69c8842266e90868c28a67a9241eb82d89da066c943b8fd0b
Evidence
5:12… PTION
6 Installs pyenv-win to $HOME\.pyenv
7 If pyenv-win is already installed, try to update to the latest version.
8
9 .PARAMETER Uninstall
10 Uninstall pyenv-win. Note that this uninstalls any Python versions that were installed with pyenv-win.
11
12 .INPUTS
13 None.
14
15 .OUTPUTS
16 None.
17
18 .EXAMPLE
19 PS> install-pyenv-win.ps1
20
21 .LINK
22 Online version: https://pyenv-win.github.io/pyenv-win/
23#>
24
25param (
26 [Switch] $Uninstall = $False
27)
28
29$PyEnvDir = "${env:USERPROFILE}\.pyenv"
30$PyEnvWinDir = "${PyEnvDir}\pyenv-win"
31$BinPath = "${PyEnvWinDir}\bin"
32$ShimsPath = "${PyEnvWinDir}\shims"
33
34Function Remove-PyEnvVars() {
35 $PathParts = [System.Environment]::GetEnvironmentVariable('PATH', "User") -Split ";"
36 $NewPathParts = $PathParts.Where{ $_ -ne $BinPath }.Where{ $_ -ne $ShimsPath }
37 $NewPath = $NewPathParts -Join ";"
38 [System.Environment]::SetEnvironmentVariable('PATH', $N …
45:26…
46 Write-Host "Removing $PyEnvDir..."
47 If (Test-Path $PyEnvDir) {
48 Remove-Item -Path $PyEnvDir -Recurse
49 }
50 Write-Host "Removing environment variables..."
51 Remove-PyEnvVars
52}
53
54Function Get-CurrentVersion() {
55 $VersionFi …
56 If (Test-Path $VersionFilePath) {
57 $CurrentVersion = Get-Content $VersionFilePath
58 }
59 Else {
⋯6 lines
66Function Get-LatestVersion() {
67 $LatestVersionFilePath = "$PyEnvDir\latest.version"
68 (New-Object System.Net.WebClient).DownloadFile("https://raw.githubusercontent.com/pyenv-win/pyenv-win/master/.version", $LatestVersionFilePath)
69 $LatestVersion = Get-Content $LatestVersionFilePath
70
71 Remove-Item -Path $LatestVersionFilePath …
102:33… install_cache", "versions", "shims"
103 ForEach ($Dir in $FoldersToBackup) {
104 If (-not (Test-Path $BackupDir)) {
105 New-Item -ItemType Directory -Path $BackupDir
106 }
107 Move-Item -Path "${PyEnvWinDir}/${Dir}" -Destination $BackupDir
108 }
109
⋯7 lines
117 $DownloadPath = "$PyEnvDir\pyenv-win.zip"
118
119 (New-Object System.Net.WebClient).DownloadFile("https://github.com/pyenv-win/pyenv-win/archive/master.zip", $DownloadPath)
120
121 Start-Process -FilePath "powershell.exe" -ArgumentList @(
122 "-NoProfile",
123 "-Command `"Microsoft.PowerShell.Archive\Expand-Archive -Path \`"$DownloadPath\`" -DestinationPath \`"$PyEnvDir\`"`""
124 ) -NoNewWindow -Wait
125
126 Move-Item -Path "$PyEnvDir\pyenv-win-master\*" -Destination "$PyEnvDir"
127 Remove-Item -Path "$PyEnvDir\pyenv-win-master" -Recurse
128 Remove-Item -Path $DownloadPath
129
130 # Update env vars
131 [System.Environment]::SetEnvironmentVariable('PYENV', "${PyEnvWi …
143:24… upDir) {
144 Write-Host "Restoring Python installations..."
145 Move-Item -Path "$BackupDir/*" -Destination $PyEnvWinDir
146 }
147
148 If ($? -eq $True) {
149 Write-Host "pyenv-win is successfully installed. You may need to close and reopen your terminal before using it."
150 }
151 Else {
152 Write-Host "pyenv-win was not i …