uv包安装网络超时解决

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
$ uv add numpy pandas torch scikit-learn matplotlib
Resolved 45 packages in 21ms
  × Failed to download `nvidia-cufft-cu12==11.3.3.83`
  ├─▶ Failed to fetch:
  │   `https://files.pythonhosted.org/packages/1f/13/ee4e00f30e676b66ae65b4f08cb5bcbb8392c03f54f2d5413ea99a5d1c80/nvidia_cufft_cu12-11.3.3.83-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl`
  ├─▶ Request failed after 3 retries
  ├─▶ error sending request for url
  │   (https://files.pythonhosted.org/packages/1f/13/ee4e00f30e676b66ae65b4f08cb5bcbb8392c03f54f2d5413ea99a5d1c80/nvidia_cufft_cu12-11.3.3.83-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl)
  ╰─▶ operation timed out
  help: If you want to add the package regardless of the failed resolution, provide the `--frozen` flag to skip locking and syncing.

这个错误是因为 uv 在尝试从官方源下载 NVIDIA 的 CUDA 组件包(nvidia-cufft-cu12)时网络超时了。

这些 NVIDIA 的包通常非常大(几百 MB),如果网络环境不够快或者连接 PyPI 官方源不稳定(在国内很常见),就会导致下载失败。

可以通过设置环境变量 UV_INDEX_URL 来让 uv 使用清华大学或阿里云的镜像源:

Linux / macOS:

1
UV_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple uv add numpy pandas torch scikit-learn matplotlib

Windows (PowerShell):

1
2
$env:UV_INDEX_URL="https://pypi.tuna.tsinghua.edu.cn/simple"
uv add numpy pandas torch scikit-learn matplotlib
Licensed under CC BY-NC-SA 4.0
使用 Hugo 构建
主题 StackJimmy 设计