UV安装并设置国内源

文章目录

一、UV下载

1.官方一键安装

bash 复制代码
# 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:临时环境变量(单次生效)

bash 复制代码
# 使用阿里云镜像源
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

添加国内镜像源

编辑文件内容如下:

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

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

bash 复制代码
uv pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ [包名]

三、验证镜像源是否生效

bash 复制代码
# 查看当前配置
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
相关推荐
ZhengEnCi1 天前
08c. 检索算法与策略-混合检索
后端·python·算法
明月_清风1 天前
Python 内存手术刀:sys.getrefcount 与引用计数的生死时速
后端·python
明月_清风1 天前
Python 消失的内存:为什么 list=[] 是新手最容易踩的“毒苹果”?
后端·python
Flittly2 天前
【从零手写 ClaudeCode:learn-claude-code 项目实战笔记】(3)TodoWrite (待办写入)
python·agent
千寻girling2 天前
一份不可多得的 《 Django 》 零基础入门教程
后端·python·面试
databook2 天前
探索视觉的边界:用 Manim 重现有趣的知觉错觉
python·动效
明月_清风2 天前
Python 性能微观世界:列表推导式 vs for 循环
后端·python
明月_清风2 天前
Python 性能翻身仗:从 O(n) 到 O(1) 的工程实践
后端·python
helloweilei3 天前
python 抽象基类
python
用户8356290780513 天前
Python 实现 PPT 转 HTML
后端·python