Python的包管理工具uv下载python版本慢问题解决
UV 是一个用 Rust 编写的 Python 包安装和依赖管理工具,当操作系统上已经安装了uv工具后,即可使用如下命令安装指定版本的python:
uv python install 3.12
但是,默认情况下,uv会去github.com上下载指定版本的python,但咱们国内访问 GitHub 的速度,可想之安装速度慢的惊人,甚至出现访问github.com地址超时的错误。此时,需要环境变量UV_PYTHON_INSTALL_MIRROR来帮忙了。
- 对于 macOS / Linux 用户 (zsh/bash):
- 打开你的终端。
- 执行下面的命令,把配置写入你的 shell 配置文件(比如 .zshrc 或 .bashrc)。
# 推荐使用自建的Github加速
echo 'export UV_PYTHON_INSTALL_MIRROR="https://gh-proxy.com/https://github.com/astral-sh/python-build-standalone/releases/download"' >> ~/.bashrc# 或者用https://ghfast.top/
# echo 'export UV_PYTHON_INSTALL_MIRROR="https://ghfast.top/https://github.com/astral-sh/python-build-standalone/releases/download"' >> ~/.bashrc# 别忘了让配置立刻生效
source ~/.bashrc
- 对于 Windows 用户:
- 想永久生效,还是得添加系统环境变量。
- 右键“此电脑” -> “属性” -> “高级系统设置” -> “环境变量”。
- 在“用户变量”或“系统变量”里,点击“新建”。
- 变量名填 UV_PYTHON_INSTALL_MIRROR
- 变量值填 https://ghfast.top/https://github.com/astral-sh/python-build-standalone/releases/download
- 一路确定,然后务必重启你的终端(PowerShell, CMD, etc.)让配置生效。