param( [string]$PythonBin = "$PSScriptRoot\..\tools\python-bin", [string]$VenvDir = "$PSScriptRoot\..\tools\python-venv" ) $ErrorActionPreference = "Stop" $PythonBin = [System.IO.Path]::GetFullPath($PythonBin) $VenvDir = [System.IO.Path]::GetFullPath($VenvDir) $PythonExe = Join-Path $PythonBin "python.exe" if (!(Test-Path $PythonExe)) { throw "未找到项目内 Python 二进制:$PythonExe" } # Windows embeddable Python 不一定带 venv 模块。优先尝试 venv;失败则使用同目录作为隔离 Python 环境安装 pip。 try { & $PythonExe -m venv $VenvDir $VenvPython = Join-Path $VenvDir "Scripts\python.exe" & $VenvPython -m pip install --upgrade pip setuptools wheel & $VenvPython -m pip install aqtinstall Write-Host "已创建虚拟环境:$VenvDir" } catch { Write-Warning "venv 创建失败,改用项目内 embeddable Python 自身作为隔离环境。" & $PythonExe (Join-Path $PythonBin "get-pip.py") & $PythonExe -m pip install --upgrade pip setuptools wheel & $PythonExe -m pip install aqtinstall Write-Host "已在项目内 Python 二进制目录安装 pip/aqtinstall:$PythonBin" }