Fix Python 3.11 detection in the Windows build script
sys.version_info[:2] prints '(3, 11)', so the old substring check for '3.11' always failed even on a valid Python install. Probe the major.minor string explicitly and support the py launcher or python on PATH. Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Code
parent
addd00364d
commit
b262b1e664
+13
-9
@@ -10,15 +10,19 @@ $Root = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
Set-Location $Root
|
||||
|
||||
function Get-Python {
|
||||
$candidates = @("py -3.11", "py -3", "python")
|
||||
$candidates = @(
|
||||
@{ Command = "py"; Arguments = @("-3.11") },
|
||||
@{ Command = "py"; Arguments = @("-3") },
|
||||
@{ Command = "python"; Arguments = @() },
|
||||
@{ Command = "python3"; Arguments = @() }
|
||||
)
|
||||
foreach ($candidate in $candidates) {
|
||||
try {
|
||||
$parts = $candidate.Split(" ")
|
||||
$exe = $parts[0]
|
||||
$exeArgs = @($parts | Select-Object -Skip 1)
|
||||
$output = & $exe @exeArgs -c "import sys; print(sys.executable); print(sys.version_info[:2])" 2>$null
|
||||
if ($LASTEXITCODE -eq 0 -and $output -match "3\.11") {
|
||||
return $parts
|
||||
$exe = $candidate.Command
|
||||
$exeArgs = @($candidate.Arguments)
|
||||
$probe = & $exe @exeArgs -c "import sys; print('{0}.{1}'.format(sys.version_info[0], sys.version_info[1]))" 2>$null
|
||||
if ($LASTEXITCODE -eq 0 -and (($probe | Out-String).Trim() -eq "3.11")) {
|
||||
return $candidate
|
||||
}
|
||||
} catch { }
|
||||
}
|
||||
@@ -31,8 +35,8 @@ $python = Get-Python
|
||||
|
||||
if (-not (Test-Path $venv)) {
|
||||
Write-Host "Creating build environment..."
|
||||
$pythonExe = $python[0]
|
||||
$pythonArgs = @($python | Select-Object -Skip 1)
|
||||
$pythonExe = $python.Command
|
||||
$pythonArgs = @($python.Arguments)
|
||||
& $pythonExe @pythonArgs -m venv $venv
|
||||
}
|
||||
$py = Join-Path $venv "Scripts\python.exe"
|
||||
|
||||
Reference in New Issue
Block a user