353 字
2 分钟
uv 换源 (设置镜像源)
TIP

本文中的 Linux 路径在 Windows 上同理 (如 /home/wyf9/.config/uv/uv.toml -> C:\Users\wyf9\.config\uv\uv.toml)
Mac: 没用过,自己改

TL; DR#

Too long, didn’t read

Terminal window
# Linux
nano /home/$USER/.config/uv/uv.toml
Terminal window
:: Windows
notepad C:\Users\%USERNAME%\.config\uv\uv.toml
uv.toml
index = [
{url = "https://pypi.tuna.tsinghua.edu.cn/simple/"},
{url = "https://mirrors.aliyun.com/pypi/simple/"},
{url = "https://mirror.sjtu.edu.cn/pypi/web/simple/"},
{url = "https://mirrors.ustc.edu.cn/pypi/web/simple/"},
{url = "https://mirrors.cernet.edu.cn/pypi/web/simple"}
]

TS; JR#

Too short, just read

官方文档: https://docs.astral.sh/uv/concepts/configuration-files/

从以上文档中, 我们便可以知道:

  • uv 的配置文件在 ~/.config/uv/uv.toml
  • 可以在里面配置镜像源

如果你只想设置一个镜像源:

uv.toml
[[index]]
url = "https://pypi.tuna.tsinghua.edu.cn/simple/"
default = true

如果想设置多个:

uv.toml
[[index]]
url = "https://pypi.tuna.tsinghua.edu.cn/simple/"
default = true
[[index]]
url = "https://mirrors.cernet.edu.cn/pypi/web/simple"
default = true

也可以用这样的格式:

uv.toml
index = [
{url = "https://pypi.tuna.tsinghua.edu.cn/simple/"},
{url = "https://mirrors.aliyun.com/pypi/simple/"},
{url = "https://mirror.sjtu.edu.cn/pypi/web/simple/"},
{url = "https://mirrors.ustc.edu.cn/pypi/web/simple/"},
{url = "https://mirrors.cernet.edu.cn/pypi/web/simple"}
]

常用的镜像列表#

TIP

镜像描述 -> Grok

国内最稳定、更新及时的镜像之一。

下载速度快,适合大规模使用。

学术镜像,包完整度高。

教育机构镜像,稳定可靠。

轻量级镜像,速度中等。

商业镜像,覆盖全面。

云服务提供商镜像,下载高效。

老牌镜像,适合备用。

教育镜像,更新较快。

pip 如何设置#

临时:

Terminal window
pip install fastapi -i MIRROR-URL

永久:

Terminal window
pip config set global.index-url MIRROR-URL
TIP

将上面的 MIRROR-URL 替换为你的镜像地址

uv 换源 (设置镜像源)
https://wyf9.top/posts/uv-mirror/
作者
1224HuangJin
发布于
2025-10-01
许可协议
CC BY-NC-SA 4.0