Improve Windows installer fallback for Python 3.13

This commit is contained in:
thePR0M3TH3AN
2025-07-06 21:28:04 -04:00
parent ff8f4f796b
commit dcd7cc8329
2 changed files with 53 additions and 3 deletions

View File

@@ -79,10 +79,11 @@ Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManage
``` ```
The Windows installer will attempt to install Git automatically if it is not already available. It also tries to The Windows installer will attempt to install Git automatically if it is not already available. It also tries to
install Python 3 using `winget`, `choco`, or `scoop` when Python is missing and recognizes the `py` launcher if `python` install Python 3 using `winget`, `choco`, or `scoop` when Python is missing and recognizes the `py` launcher if `python`
isn't on your PATH. If automatic installation fails, you'll be shown a link to download Python directly from isn't on your PATH. If these tools are unavailable you'll see a link to download Python directly from
<https://www.python.org/downloads/windows/>. <https://www.python.org/downloads/windows/>. When Python 3.13 or newer is detected without the Microsoft C++ build tools,
the installer now attempts to download Python 3.12 automatically so you don't have to compile packages from source.
**Note:** If you are using Python 3.13 or newer, install the [Microsoft Visual C++ Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/) and reopen PowerShell before rerunning the installer. **Note:** If this fallback fails, install Python 3.12 manually or install the [Microsoft Visual C++ Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/) and rerun the installer.
*Install the beta branch:* *Install the beta branch:*
```powershell ```powershell
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; $scriptContent = (New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/PR0M3TH3AN/SeedPass/main/scripts/install.ps1'); & ([scriptblock]::create($scriptContent)) -Branch beta Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; $scriptContent = (New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/PR0M3TH3AN/SeedPass/main/scripts/install.ps1'); & ([scriptblock]::create($scriptContent)) -Branch beta

View File

@@ -100,6 +100,27 @@ function Get-PythonCommand {
return $null return $null
} }
# Try to locate a specific Python version using the `py` launcher or
# versioned executables like `python3.12`.
function Get-PythonCommandByVersion {
param([string]$Version)
$cmd = Get-Command py -ErrorAction SilentlyContinue
if ($cmd) {
$out = & $cmd -$Version --version 2>&1
if ($LASTEXITCODE -eq 0 -and $out -match '^Python') {
return @('py', "-$Version")
}
}
$cmd = Get-Command "python$Version" -ErrorAction SilentlyContinue
if ($cmd) {
$out = & $cmd --version 2>&1
if ($LASTEXITCODE -eq 0 -and $out -match '^Python') {
return ,("python$Version")
}
}
return $null
}
$PythonCmd = Get-PythonCommand $PythonCmd = Get-PythonCommand
if (-not $PythonCmd) { if (-not $PythonCmd) {
Write-Warning "Python 3 is not installed. Attempting to install..." Write-Warning "Python 3 is not installed. Attempting to install..."
@@ -133,6 +154,34 @@ if ($pyVersion -and $pyVersion.Major -eq 3 -and $pyVersion.Minor -ge 13) {
# Ensure C++ build tools are available before installing dependencies # Ensure C++ build tools are available before installing dependencies
Ensure-BuildTools Ensure-BuildTools
# If build tools are still missing and Python 3.13+ is in use, try to
# install Python 3.12 automatically since many packages lack wheels for
# newer versions.
$buildOk = Get-Command cl.exe -ErrorAction SilentlyContinue
if (-not $buildOk -and $pyVersion -and $pyVersion.Major -eq 3 -and $pyVersion.Minor -ge 13) {
Write-Warning "No Microsoft C++ Build Tools detected and Python $pyVersionString is in use."
Write-Info "Attempting to install Python 3.12 for compatibility..."
if (Get-Command winget -ErrorAction SilentlyContinue) {
try { winget install --id Python.Python.3.12 -e --source winget -h } catch { Write-Warning "Failed to install Python 3.12 via winget." }
} elseif (Get-Command choco -ErrorAction SilentlyContinue) {
try { choco install python --version=3.12 -y } catch { Write-Warning "Failed to install Python 3.12 via Chocolatey." }
} elseif (Get-Command scoop -ErrorAction SilentlyContinue) {
try { scoop install python@3.12 } catch { Write-Warning "Failed to install Python 3.12 via Scoop." }
} else {
Write-Warning "Please install Python 3.12 manually from https://www.python.org/downloads/windows/"
}
$env:Path = [System.Environment]::GetEnvironmentVariable('Path','Machine') + ';' +
[System.Environment]::GetEnvironmentVariable('Path','User')
$py12 = Get-PythonCommandByVersion '3.12'
if ($py12) {
Write-Info "Using Python 3.12 for installation."
$PythonCmd = $py12
} else {
Write-Warning "Python 3.12 not found after installation attempt."
}
}
# 2. Clone or update the repository # 2. Clone or update the repository
if (Test-Path (Join-Path $InstallDir ".git")) { if (Test-Path (Join-Path $InstallDir ".git")) {
Write-Info "SeedPass directory found. Fetching updates and switching to '$Branch' branch..." Write-Info "SeedPass directory found. Fetching updates and switching to '$Branch' branch..."