fix: detect Windows App Alias fake python in install script

Windows 10/11 ships with App Execution Aliases that redirect python.exe
to Microsoft Store. The installer now detects this stub and provides
specific guidance to install real Python and disable the alias.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
jim800121chen 2026-03-23 12:45:34 +08:00
parent 2d68387ed1
commit de7df88ce3

View File

@ -134,19 +134,38 @@ if ($libusbFound) {
Write-Step "3/5 Setting up Kneron hardware environment"
$pythonCmd = $null
# Try python3 first, then python (Windows often uses 'python' for Python 3)
if (Get-Command python3 -ErrorAction SilentlyContinue) {
# Helper: check if a python command is a real install (not Windows Store App Alias)
function Test-RealPython($cmd) {
$cmdInfo = Get-Command $cmd -ErrorAction SilentlyContinue
if (-not $cmdInfo) { return $false }
# Windows App Alias lives under WindowsApps — it's a stub, not real Python
if ($cmdInfo.Source -match 'WindowsApps') { return $false }
try {
$ver = & $cmd --version 2>&1
if ($ver -match "Python 3") { return $true }
} catch {}
return $false
}
if (Test-RealPython "python3") {
$pythonCmd = "python3"
} elseif (Get-Command python -ErrorAction SilentlyContinue) {
$pyVer = & python --version 2>&1
if ($pyVer -match "Python 3") {
$pythonCmd = "python"
}
} elseif (Test-RealPython "python") {
$pythonCmd = "python"
}
if (-not $pythonCmd) {
Write-Warn "Python 3 not found. Skipping Kneron hardware setup."
Write-Warn " Install: winget install Python.Python.3.12"
# Detect App Alias to give a more specific hint
$storeAlias = Get-Command python -ErrorAction SilentlyContinue
if ($storeAlias -and $storeAlias.Source -match 'WindowsApps') {
Write-Warn "Detected Windows Store App Alias for Python (not a real installation)."
Write-Warn " Please install Python and ensure the App Alias is disabled:"
Write-Warn " 1. Run: winget install Python.Python.3.12"
Write-Warn " 2. Settings > Apps > Advanced app settings > App execution aliases"
Write-Warn " -> Turn OFF 'python.exe' and 'python3.exe'"
} else {
Write-Warn "Python 3 not found. Skipping Kneron hardware setup."
Write-Warn " Install: winget install Python.Python.3.12"
}
} else {
$pyVersion = & $pythonCmd --version 2>&1
Write-Info "Python: $pyVersion"