From 1ed751c4dcdea4c7afa7d8ed752ae93fad891a30 Mon Sep 17 00:00:00 2001 From: fei550 <1420031550@qq.com> Date: Thu, 2 Jul 2026 15:46:33 +0800 Subject: [PATCH] fix: improve wheel download script reliability --- README.md | 2 ++ scripts/download_wheels.ps1 | 30 ++++++++++++++++++++++++++---- scripts/install_offline.ps1 | 14 +++++++++++--- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e689f9a..9a25f6e 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,8 @@ .\scripts\install_offline.ps1 ``` +如果在线下载 wheel,默认走 `https://pypi.org/simple`,私有镜像可加 `-IndexUrl`。 + 启动服务: ```powershell diff --git a/scripts/download_wheels.ps1 b/scripts/download_wheels.ps1 index eef4d8a..5ad9ed5 100644 --- a/scripts/download_wheels.ps1 +++ b/scripts/download_wheels.ps1 @@ -1,5 +1,6 @@ param( - [switch]$NoPause + [switch]$NoPause, + [string]$IndexUrl = "https://pypi.org/simple" ) $ErrorActionPreference = "Stop" @@ -23,6 +24,27 @@ function Get-PythonCommand { throw "Python was not found. Install Python 3.10+ before downloading wheels." } +function Invoke-PipDownload { + param( + [string]$PythonCommand, + [string[]]$PythonArgs + ) + + $pipArgs = @( + "-m", "pip", "download", + "--index-url", $IndexUrl, + "--trusted-host", "pypi.org", + "--trusted-host", "files.pythonhosted.org", + "--disable-pip-version-check", + "--retries", "3", + "--timeout", "60", + "-r", $Req, + "-d", $WheelDir + ) + + & $PythonCommand @PythonArgs @pipArgs +} + try { Set-Location $Root if (-not (Test-Path $Req)) { @@ -34,13 +56,13 @@ try { Write-Host "Downloading offline wheels to: $WheelDir" -ForegroundColor Cyan if ($python -eq "py") { - & py -3 -m pip download -r $Req -d $WheelDir + Invoke-PipDownload -PythonCommand "py" -PythonArgs @("-3") } else { - & $python -m pip download -r $Req -d $WheelDir + Invoke-PipDownload -PythonCommand $python -PythonArgs @() } if ($LASTEXITCODE -ne 0) { - throw "Wheel download failed. Check network access and pip." + throw "Wheel download failed. Check network access to $IndexUrl. If your environment uses a private PyPI mirror, pass -IndexUrl with the mirror address." } Write-Host "" diff --git a/scripts/install_offline.ps1 b/scripts/install_offline.ps1 index e62084c..edaf610 100644 --- a/scripts/install_offline.ps1 +++ b/scripts/install_offline.ps1 @@ -1,5 +1,6 @@ param( - [switch]$NoPause + [switch]$NoPause, + [string]$IndexUrl = "https://pypi.org/simple" ) $ErrorActionPreference = "Stop" @@ -130,11 +131,18 @@ function Install-Requirements { & $VenvPython -m pip install --no-index --find-links $WheelDir -r $Req } else { Write-Host "No offline wheels found. Installing dependencies from the network." - & $VenvPython -m pip install -r $Req + & $VenvPython -m pip install ` + --index-url $IndexUrl ` + --trusted-host pypi.org ` + --trusted-host files.pythonhosted.org ` + --disable-pip-version-check ` + --retries 3 ` + --timeout 60 ` + -r $Req } if ($LASTEXITCODE -ne 0) { - throw "Dependency installation failed. If the server is offline, run scripts\download_wheels.ps1 on an online machine first and copy vendor\wheels to this server." + throw "Dependency installation failed. Check network access to $IndexUrl. If the server is offline, run scripts\download_wheels.ps1 on an online machine first and copy vendor\wheels to this server." } }