在使用uv安装Python的时候经常会遇到下载卡顿或者现在到一半的时候断开下载的情况,配置下载源为国内下载源科技解决这个问题

编辑uv的配置文件,如果文件不存在新建一个文件

vim ~/.config/uv/uv.toml

写入以下内容:

# 阿里源加速Python本体下载
python-install-mirror = "https://registry.npmmirror.com/-/binary/python-build-standalone/"
[[index]]
# 清华源加速依赖包下载
url = "https://pypi.tuna.tsinghua.edu.cn/simple/"
default = true

python-install-mirror 当你下载Python时的下载地址,当你执行下面命令的时候,会从阿里源下载Python本体。

uv python install cpython-3.12
uv python install cpython-3.12.10
uv python install cpython-3.13
uv python install cpython-3.13.3

index.url 当你执行 uv add 时下载软件包的地址,和使用 pip install 是一样的。

uv add pillow pandas

保存后退出当前终端,重新进入终端配置文件就生效了,配置后下载速度显著提升。

在无网络环境要执行uv python install也可以手动下载并安装:

  1. 收动下载CPython 3.12安装包(如 cpython-3.12.10+xxxx-x86_64.tar.gz)
  2. 将包放入本地目录(例如 /mnt/workspace/python_cache)
  3. 设置环境变量
export UV_PYTHON_INSTALL_MIRROR="file:///mnt/workspace/python_cache"  # Linux/Mac
set UV_PYTHON_INSTALL_MIRROR="file:///D:/python_cache"   # Windows
  1. 执行 python install cpython-3.12.10