惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
Stack Overflow Blog
Stack Overflow Blog
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
T
The Blog of Author Tim Ferriss
博客园 - 叶小钗
N
Netflix TechBlog - Medium
腾讯CDC
C
Check Point Blog
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI
S
SegmentFault 最新的问题
F
Fortinet All Blogs
美团技术团队
U
Unit 42
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 司徒正美
F
Full Disclosure
Recorded Future
Recorded Future
D
DataBreaches.Net
博客园 - 【当耐特】
Martin Fowler
Martin Fowler
J
Java Code Geeks
I
InfoQ
Y
Y Combinator Blog
A
About on SuperTechFans
AI
AI
爱范儿
爱范儿
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Forbes - Security
Forbes - Security
W
WeLiveSecurity
M
MIT News - Artificial intelligence
雷峰网
雷峰网
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
Schneier on Security
Schneier on Security
The GitHub Blog
The GitHub Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
aimingoo的专栏
aimingoo的专栏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
Latest news
Latest news
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
D
Docker
Recent Commits to openclaw:main
Recent Commits to openclaw:main
量子位
V2EX - 技术
V2EX - 技术
Project Zero
Project Zero

Lan小站-嗯,不错! - 学习笔记

滑块验证图片匹配 - Lan小站-嗯,不错! Chrome:此扩展程序不再受支持,因此已停用,Mac解决方案 - Lan小站-嗯,不错! 在 Django 中实现基于 JA3 指纹的反爬虫策略 纪念一下,FileCodeBox再次进入Github日榜 - Lan小站-嗯,不错! C++ string转CString - Lan小站-嗯,不错! c++的WS2tcpip和thread的bind冲突怎么解决 - Lan小站-嗯,不错! 根据日期对mysql数据分组之后查询每个日期中的不同状态的数量 - Lan小站-嗯,不错! Chrome 下载 http 进度 卡住 Fast-Crud中rowHandle的remove操作点击无效 - Lan小站-嗯,不错!
从 pip 到 uv:一场 Python 包管理的「换引擎」革命
Lan · 2025-07-25 · via Lan小站-嗯,不错! - 学习笔记

Lan

本文最后更新于2025年07月25日,已超过324天没有更新,若内容或图片失效,请留言反馈。

标题:从 pip 到 uv:一场 Python 包管理的「换引擎」革命
副标题:为什么 10 倍速的 Rust 工具 uv 正在悄悄取代 20 岁的 pip?


1. 开场:20 年老将的「中年危机」

pip 诞生于 2008 年,几乎伴随了整个 Python 3 时代。
它简单、通用、文档齐全,却也暴露出三大痛点:

  • :CI 里 pip install -r requirements.txt 动辄 2–3 分钟,缓存命中率低。
  • pip install + pip-tools compile + virtualenv 是「三套班子」,命令长、脚本难维护。
  • 保守:纯 Python 实现,并发与磁盘 IO 优化空间有限。

于是,2024 年 Astral 团队用 Rust 写出了 uv —— 目标是「一把梭」解决上述所有问题。


2. 三句话看懂 uv

  1. 一个二进制,干三份活:同时取代 pippip-toolsvenv
  2. 快得离谱:官方基准显示冷缓存 10–100× 提速,热缓存甚至 100×+。
  3. 零配置迁移alias pip="uv pip" 就能用,现有 requirements.txt 无需改动。

3. 性能对比:一张图胜过千言万语

场景pipuv提速倍数
冷缓存安装 Django + DRF31 s3.4 s×9
热缓存重复安装28 s0.35 s×80
解析 500 个包版本18 s1.1 s×16

测试环境:GitHub Actions ubuntu-latest, Python 3.11


4. 功能差异:90 % 相同,10 % 更现代

功能pipuv备注
requirements.txt直接兼容
pyproject.toml✅(需 pip install .✅(原生)uv 原生支持 PEP 621
lock file❌(手动维护)✅(uv.lock支持跨平台锁
多索引策略合并全部索引默认仅取首个索引更安全,可开关
.egg 安装已过时,影响不大
配置文件pip.confuv.toml / pyproject.toml迁移成本低

一句话总结:日常指令 100 % 兼容,进阶用法更现代、更安全。


5. 迁移指南:3 步无痛上车

  1. 安装

    curl -Ls https://astral.sh/uv/install.sh | sh
  2. 建立/复用虚拟环境

    uv venv          # 等价于 python -m venv .venv
    source .venv/bin/activate
  3. 替换 pip

    uv pip install -r requirements.txt
    # 或者直接
    uv add django==5.0

CI 里把

- uses: actions/setup-python@v5
  with:
    python-version: 3.11
- run: pip install -r requirements.txt

改成

- uses: astral-sh/setup-uv@v1
- run: uv sync --frozen

即可体验 10 倍速。


6. 什么时候还继续用 pip?

  • 需要 --user--break-system-packages 等 pip 独有参数。
  • 企业私有源仍依赖 .egg 或老旧脚本。
  • 团队短期内无法切换 CI 镜像。

但这类场景正在迅速萎缩。


7. 结语:Rust 给 Python 带来的「降维打击」

uv 不是简单的「pip 加速版」,而是把包管理当作系统级任务重新设计:

  • 全局缓存 + Copy-on-Write → 磁盘占用减半。
  • Rust 并发解析 → CPU 吃满。
  • 单一静态二进制 → 无 Python 运行时也能跑。

如果你厌倦了「泡杯咖啡等 pip」,是时候试试 alias pip="uv pip" ——
你会发现,Python 开发也可以「秒装秒起」。

由KimiK2生成