-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyInstallerBootstrap.ps1
64 lines (53 loc) · 2.15 KB
/
pyInstallerBootstrap.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
if ((Get-Command python -ErrorAction SilentlyContinue) -and (Get-Command python).CommandType -eq "Application") {
Remove-Item $env:USERPROFILE\AppData\Local\Microsoft\WindowsApps\python*.exe
}
$global:ProgressPreference = 'SilentlyContinue'
$pythonCommand = Get-Command python -ErrorAction SilentlyContinue
if (-not $pythonCommand) {
Write-Host "Python is not installed. Installing Python..."
$url = "https://www.python.org/ftp/python/3.10.6/python-3.10.6-amd64.exe"
$localPath = "C:\vagrant\python-3.10.6-amd64.exe"
if (-not (Test-Path -Path $localPath)) {
Invoke-WebRequest -Uri $url -UseBasicParsing -OutFile $localPath
} else {
Write-Host "Not redownloading. File already exists at $localPath"
}
& $localPath /quiet InstallAllUsers=1 PrependPath=1
$newPythonPath = "$env:ProgramFiles\Python310"
$newPythonScriptsPath = "$env:ProgramFiles\Python310\Scripts"
$env:Path += ";$newPythonPath;$newPythonScriptsPath"
# Wait for 10 seconds before checking for Python installation
Start-Sleep -Seconds 10
} elseif ($pythonCommand.CommandType -eq "Application") {
Write-Host "Python is already installed."
}
# Wait for Python installation to complete
$pythonExePath = "$env:ProgramFiles\Python310\python.exe"
$timeout = 300
$elapsed = 0
while (-not (Test-Path $pythonExePath) -and $elapsed -lt $timeout) {
Start-Sleep -Seconds 1
$elapsed += 1
}
if ($elapsed -eq $timeout) {
Write-Host "Python installation timed out after $timeout seconds."
exit 1
}
# Wait for pip to become available
$pipTimeout = 60
$pipElapsed = 0
while (-not (& $pythonExePath -m pip --version 2> $null) -and $pipElapsed -lt $pipTimeout) {
Start-Sleep -Seconds 1
$pipElapsed += 1
}
if ($pipElapsed -eq $pipTimeout) {
Write-Host "Pip not available after $pipTimeout seconds."
exit 1
}
if (-not (& $pythonExePath -m pip list | Select-String -Pattern "^pyinstaller\s")) {
Write-Host "PyInstaller is not installed. Installing PyInstaller..."
# Install pyinstaller using the full path of the Python executable
& $pythonExePath -m pip install pyinstaller
} else {
Write-Host "PyInstaller is already installed."
}