Prefer Python 3.11+ in Windows launcher
This commit is contained in:
@@ -30,23 +30,60 @@ function Fail($msg) {
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 1. Locate a Python interpreter (3.11+ recommended)
|
||||
# 1. Locate a Python interpreter (3.11+ required)
|
||||
Write-Step "Checking for Python"
|
||||
function Get-PythonVersionText($launcher, $launcherArgs) {
|
||||
try {
|
||||
return (& $launcher @launcherArgs -c "import sys; print('.'.join(map(str, sys.version_info[:3])))" 2>$null).Trim()
|
||||
} catch {
|
||||
return $null
|
||||
}
|
||||
}
|
||||
|
||||
$pyExe = $null
|
||||
foreach ($c in @("python", "py")) {
|
||||
$cmd = Get-Command $c -ErrorAction SilentlyContinue
|
||||
if ($cmd) { $pyExe = $cmd.Source; break }
|
||||
$pyArgs = @()
|
||||
$pyVersion = $null
|
||||
|
||||
$pyLauncher = Get-Command py -ErrorAction SilentlyContinue
|
||||
if ($pyLauncher) {
|
||||
foreach ($v in @("-3.13", "-3.12", "-3.11")) {
|
||||
$ver = Get-PythonVersionText $pyLauncher.Source @($v)
|
||||
if ($ver) {
|
||||
$pyExe = $pyLauncher.Source
|
||||
$pyArgs = @($v)
|
||||
$pyVersion = $ver
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (-not $pyExe) {
|
||||
Fail "Python not found on PATH. Install Python 3.11+ from https://www.python.org/downloads/ (check 'Add to PATH'), then re-run this script."
|
||||
$pythonCmd = Get-Command python -ErrorAction SilentlyContinue
|
||||
if ($pythonCmd) {
|
||||
$ver = Get-PythonVersionText $pythonCmd.Source @()
|
||||
if ($ver) {
|
||||
$versionParts = $ver.Split('.')
|
||||
$major = [int]$versionParts[0]
|
||||
$minor = [int]$versionParts[1]
|
||||
if ($major -gt 3 -or ($major -eq 3 -and $minor -ge 11)) {
|
||||
$pyExe = $pythonCmd.Source
|
||||
$pyVersion = $ver
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Write-Host ("Using Python: " + $pyExe)
|
||||
|
||||
if (-not $pyExe) {
|
||||
Fail "Couldn't find Python 3.11+ for Windows setup. Install Python 3.11+ (or open the Python launcher with 'py -3.11') from https://www.python.org/downloads/, then re-run this script."
|
||||
}
|
||||
$pythonLabel = ("Using Python {0}: {1} {2}" -f $pyVersion, $pyExe, ($pyArgs -join ' ')).TrimEnd()
|
||||
Write-Host $pythonLabel
|
||||
|
||||
# 2. Create the virtualenv if missing
|
||||
$venvPy = Join-Path $PSScriptRoot "venv\Scripts\python.exe"
|
||||
if (-not (Test-Path $venvPy)) {
|
||||
Write-Step "Creating virtual environment (venv)"
|
||||
& $pyExe -m venv venv
|
||||
& $pyExe @pyArgs -m venv venv
|
||||
if ($LASTEXITCODE -ne 0 -or -not (Test-Path $venvPy)) { Fail "Failed to create the virtual environment." }
|
||||
} else {
|
||||
Write-Host "venv already exists - skipping creation."
|
||||
|
||||
Reference in New Issue
Block a user