UV设置下载镜像

设置Python下载镜像

uv下载python是通过https://github.com/indygreg/python-build-standalone项目的releases进行下载,uv本身提供了下载镜像参数UV_PYTHON_INSTALL_MIRROR

1
2
export UV_PYTHON_INSTALL_MIRROR=https://github.com/indygreg/python-build-standalone/releases/download
uv python install 3.13.1

长期使用可以添加到~/.bashrc

1
2
# .bashrc
export UV_PYTHON_INSTALL_MIRROR=https://github.com/indygreg/python-build-standalone/releases/download

设置Packages下载镜像

uv可以像pip一样管理依赖,但是uv不会读取pip的配置,所以要单独设置镜像地址。

uv本身提供的设置默认下载地址的环境变量名称为UV_DEFAULT_INDEX.

除了环境变量,还可以改配置文件、设置选项等.

这里以清华Pypi镜像源为例子

临时使用

1
ux add --default-index https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple requests

长期使用

可以更改项目的配置文件pyproject.toml或者uv.toml,也可以设置.bashrc

1
2
3
4
5
# pyproject.toml
[[tool.uv.index]]
url = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple"
default = true

1
2
3
4
# uv.toml
[[index]]
url = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple"
default = true
1
2
# .bashrc
export UV_DEFAULT_INDEX="https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple"