|
|
@@ -221,6 +221,90 @@ if (-not $pythonExe) {
|
|
|
}
|
|
|
Write-Host '[OK] python found' -ForegroundColor Green
|
|
|
|
|
|
+Write-Host ''
|
|
|
+Write-Host 'Embedded Python (py): prefer backup restore, network only as last fallback...' -ForegroundColor Yellow
|
|
|
+$pyEmbeddedExe = Join-Path $pythonRoot 'py\python.exe'
|
|
|
+$embSitePackages = Join-Path $pythonRoot 'py\Lib\site-packages'
|
|
|
+$bakRoot = Join-Path $pythonRoot 'backup'
|
|
|
+$bakSitePackages = Join-Path $pythonRoot 'backup\site-packages'
|
|
|
+$pypiIndexUrl = 'https://pypi.tuna.tsinghua.edu.cn/simple'
|
|
|
+$pypiTrustedHost = 'pypi.tuna.tsinghua.edu.cn'
|
|
|
+New-Item -ItemType Directory -Force -Path $bakRoot | Out-Null
|
|
|
+New-Item -ItemType Directory -Force -Path $bakSitePackages | Out-Null
|
|
|
+if (Test-Path $pyEmbeddedExe) {
|
|
|
+ $embeddedPipOk = $false
|
|
|
+ $toolchainOk = $false
|
|
|
+ & $pyEmbeddedExe -m pip --version 2>$null | Out-Null
|
|
|
+ if ($LASTEXITCODE -eq 0) { $embeddedPipOk = $true }
|
|
|
+
|
|
|
+ if (-not $embeddedPipOk) {
|
|
|
+ Write-Host '[WARN] Embedded pip missing or broken; restoring from backup\site-packages (copy)...' -ForegroundColor Yellow
|
|
|
+ Get-ChildItem -LiteralPath $bakSitePackages -ErrorAction SilentlyContinue | ForEach-Object {
|
|
|
+ Copy-Item -LiteralPath $_.FullName -Destination $embSitePackages -Recurse -Force
|
|
|
+ }
|
|
|
+ & $pyEmbeddedExe -m pip --version 2>$null | Out-Null
|
|
|
+ if ($LASTEXITCODE -eq 0) {
|
|
|
+ $embeddedPipOk = $true
|
|
|
+ Write-Host '[OK] pip restored from local backup (no download)' -ForegroundColor Green
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($embeddedPipOk) {
|
|
|
+ & $pyEmbeddedExe -c "import pip,setuptools,wheel; import setuptools.build_meta" 2>$null | Out-Null
|
|
|
+ if ($LASTEXITCODE -eq 0) { $toolchainOk = $true }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (-not $toolchainOk) {
|
|
|
+ Write-Host '[WARN] pip/setuptools/wheel incomplete; restore from backup\site-packages (copy)...' -ForegroundColor Yellow
|
|
|
+ Get-ChildItem -LiteralPath $bakSitePackages -ErrorAction SilentlyContinue | ForEach-Object {
|
|
|
+ Copy-Item -LiteralPath $_.FullName -Destination $embSitePackages -Recurse -Force
|
|
|
+ }
|
|
|
+ if ($embeddedPipOk) {
|
|
|
+ & $pyEmbeddedExe -c "import pip,setuptools,wheel; import setuptools.build_meta" 2>$null | Out-Null
|
|
|
+ if ($LASTEXITCODE -eq 0) {
|
|
|
+ $toolchainOk = $true
|
|
|
+ Write-Host '[OK] toolchain restored from backup copy' -ForegroundColor Green
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (-not $toolchainOk -and $embeddedPipOk) {
|
|
|
+ Write-Host '[WARN] backup copy not enough; trying backup whl offline install...' -ForegroundColor Yellow
|
|
|
+ & $pyEmbeddedExe -m pip install --no-index --find-links $bakRoot --upgrade pip setuptools wheel
|
|
|
+ & $pyEmbeddedExe -c "import pip,setuptools,wheel; import setuptools.build_meta" 2>$null | Out-Null
|
|
|
+ if ($LASTEXITCODE -eq 0) {
|
|
|
+ $toolchainOk = $true
|
|
|
+ Write-Host '[OK] toolchain repaired from backup wheels (offline)' -ForegroundColor Green
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (-not $toolchainOk -and $embeddedPipOk) {
|
|
|
+ Write-Host '[WARN] offline backup not enough; upgrading via Tsinghua mirror...' -ForegroundColor Yellow
|
|
|
+ & $pyEmbeddedExe -m pip install -i $pypiIndexUrl --trusted-host $pypiTrustedHost --upgrade pip setuptools wheel
|
|
|
+ & $pyEmbeddedExe -c "import pip,setuptools,wheel; import setuptools.build_meta" 2>$null | Out-Null
|
|
|
+ if ($LASTEXITCODE -eq 0) {
|
|
|
+ $toolchainOk = $true
|
|
|
+ Write-Host '[OK] toolchain repaired via online upgrade' -ForegroundColor Green
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($toolchainOk) {
|
|
|
+ foreach ($pkgDir in @('pip', 'setuptools', 'wheel', 'pkg_resources')) {
|
|
|
+ $fromPkg = Join-Path $embSitePackages $pkgDir
|
|
|
+ if (Test-Path $fromPkg) {
|
|
|
+ Copy-Item -LiteralPath $fromPkg -Destination (Join-Path $bakSitePackages $pkgDir) -Recurse -Force
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Get-ChildItem -LiteralPath $embSitePackages -Directory -ErrorAction SilentlyContinue | Where-Object { $_.Name -match '^(pip|setuptools|wheel)-.+\.dist-info$' } | ForEach-Object {
|
|
|
+ Copy-Item -LiteralPath $_.FullName -Destination (Join-Path $bakSitePackages $_.Name) -Recurse -Force
|
|
|
+ }
|
|
|
+ & $pyEmbeddedExe -m pip download pip setuptools wheel -d $bakRoot -i $pypiIndexUrl --trusted-host $pypiTrustedHost 2>$null
|
|
|
+ Write-Host '[OK] Synced py\Lib\site-packages → backup\site-packages' -ForegroundColor Green
|
|
|
+ } else {
|
|
|
+ Write-Host '[WARN] Embedded Python toolchain still broken. Use python\x64\get-pip.py or repair manually.' -ForegroundColor Yellow
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
Write-Host ''
|
|
|
Write-Host 'Running python-enviroment-install.py (creates venv if missing, installs dependencies)...' -ForegroundColor Yellow
|
|
|
if (-not $venvPath) { $venvPath = Join-Path $scriptRoot ('python\' + $arch + '\env') }
|