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
|
Set-Location $Root
|
||||||
|
|
||||||
function Get-Python {
|
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) {
|
foreach ($candidate in $candidates) {
|
||||||
try {
|
try {
|
||||||
$parts = $candidate.Split(" ")
|
$exe = $candidate.Command
|
||||||
$exe = $parts[0]
|
$exeArgs = @($candidate.Arguments)
|
||||||
$exeArgs = @($parts | Select-Object -Skip 1)
|
$probe = & $exe @exeArgs -c "import sys; print('{0}.{1}'.format(sys.version_info[0], sys.version_info[1]))" 2>$null
|
||||||
$output = & $exe @exeArgs -c "import sys; print(sys.executable); print(sys.version_info[:2])" 2>$null
|
if ($LASTEXITCODE -eq 0 -and (($probe | Out-String).Trim() -eq "3.11")) {
|
||||||
if ($LASTEXITCODE -eq 0 -and $output -match "3\.11") {
|
return $candidate
|
||||||
return $parts
|
|
||||||
}
|
}
|
||||||
} catch { }
|
} catch { }
|
||||||
}
|
}
|
||||||
@@ -31,8 +35,8 @@ $python = Get-Python
|
|||||||
|
|
||||||
if (-not (Test-Path $venv)) {
|
if (-not (Test-Path $venv)) {
|
||||||
Write-Host "Creating build environment..."
|
Write-Host "Creating build environment..."
|
||||||
$pythonExe = $python[0]
|
$pythonExe = $python.Command
|
||||||
$pythonArgs = @($python | Select-Object -Skip 1)
|
$pythonArgs = @($python.Arguments)
|
||||||
& $pythonExe @pythonArgs -m venv $venv
|
& $pythonExe @pythonArgs -m venv $venv
|
||||||
}
|
}
|
||||||
$py = Join-Path $venv "Scripts\python.exe"
|
$py = Join-Path $venv "Scripts\python.exe"
|
||||||
|
|||||||
Reference in New Issue
Block a user