UV安装并设置国内源

发布于:2025-07-30 ⋅ 阅读:(37) ⋅ 点赞:(0)

一、UV下载

1.官方一键安装

# On Windows.
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
# On macOS and Linux.
curl -LsSf https://astral.sh/uv/install.sh | sh

2.github下载安装

国内网络问题无法下载解决方案
来到github下载自己对应系统的包:
https://github.com/astral-sh/uv/releases
在这里插入图片描述

我这里以linux为例选择x86_64下载地址为:
https://github.com/astral-sh/uv/releases/download/0.8.3/uv-x86_64-unknown-linux-gnu.tar.gz

下载到本地后上传到服务器并解压缩

将uv 、 uvx 放到 /usr/local/bin下即可!!!!!!

二、更换国内镜像源(加速下载)

方法1:临时环境变量(单次生效)

# 使用阿里云镜像源
export UV_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/
uv pip install [包名]

# 或清华大学镜像源
export UV_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple/

方法2:永久配置(推荐)

创建或修改配置文件
在用户目录下创建 uv.toml 文件(路径参考):

  • Linux/macOS: ~/.config/uv/uv.toml
  • Windows: %APPDATA%\uv\uv.toml

添加国内镜像源
编辑文件内容如下:

[[index]]
url = "https://mirrors.aliyun.com/pypi/simple/"
default = true
# 或使用清华源
# url = "https://pypi.tuna.tsinghua.edu.cn/simple/"

方法3:命令行直接指定源

uv pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ [包名]

三、验证镜像源是否生效

# 查看当前配置
uv config get index.url

# 安装测试包(观察下载速度)
uv pip install numpy

常见镜像源地址

镜像名称 URL
阿里云 https://mirrors.aliyun.com/pypi/simple/
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
豆瓣 https://pypi.doubanio.com/simple/
华为云 https://repo.huaweicloud.com/repository/pypi/simple/

注意事项

  • 若同时使用 pip 和 uv,镜像源需分别配置(uv 不读取 pip 的配置)。
  • 更换源后如遇 SSL 错误,尝试将 http:// 替换为 https://。
  • 清除缓存命令:uv clean

网站公告

今日签到

点亮在社区的每一天
去签到