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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - *感悟人生*

PDFtoEXCEL批量处理高保真同步格式 JS 逆向与前端安全加固实战指南 批量处理苹果电脑的HEIF格式转成JPG|PNG 邮件群发系统 注册授权--续 独立授权模块 --可以为你的程序或者工具加上一把锁 音频转换合并切割工具 修改文件重命名(1、默认去掉预览和备份,2、默认当前文件路径) AI 平台 SQL语句解析 扣代码中,遇到this 应该怎么处理 AST解OB混淆,适用大部分的混淆 Akamai的形成与风控分析:聚焦Akamai 3.0 执行py3o的重启脚本(包含手动执行,以及自动执行的脚本) reduce与map+filter的复杂计算场景 py3o中汇总的计算:sum reduce map 三种形式来处理对比 py3o中数字金额转大写 加密解密基本概念 MJ提示词自动批处理GUI版 表单和载荷的区别,以及python和js在处理json时的空格问题。 R函数处理异步迭代,在爬虫中的作用。
uv 在 Python 开发中的常用命令详解
*感悟人生* · 2025-03-24 · via 博客园 - *感悟人生*

# uv 在 Python 开发中的常用命令详解

在 Python 开发中,`uv` 是一个兼具速度与现代化的包管理工具,它可以替代传统的 `pip`、`virtualenv`、`pip-tools` 等工具。本文将介绍 `uv` 在实际开发中的常用命令及其中文解释,帮助你快速上手并高效管理项目依赖。

---

## ✨ 什么是 uv?

[`uv`](https://github.com/astral-sh/uv) 是由 Astral 团队推出的一款极速包管理器,特点如下:

- 🚀 **速度极快**:比 `pip` 安装依赖快数倍
- 📦 **内置虚拟环境管理**:无需 `python -m venv`
- 🔁 **支持锁文件同步**:像 `pip-sync` 一样保证环境一致
- 🧼 **自动缓存和依赖优化**

---

## 📦 安装 uv

使用 pip 安装:

```bash
pip install uv

安装后确认版本

uv --version

🛠️ 常用命令详解

1️⃣ 创建虚拟环境

uv venv

在当前目录创建 .venv 虚拟环境(类似 python -m venv .venv),无需手动激活,uv 命令会自动识别并使用它。

2️⃣ 安装单个依赖包

uv pip install fastapi

替代 pip install,支持 PyPI、GitHub、wheel、压缩包等多种安装方式。

3️⃣ 从 requirements.txt 安装依赖

uv pip install -r requirements.txt

安装项目所需全部依赖,适用于新项目环境初始化。

4️⃣ 升级已有包

6️⃣ 查看当前安装的包

uv pip list

显示当前虚拟环境中所有已安装的库及版本。

7️⃣ 导出依赖(冻结)

uv pip freeze > requirements.txt

导出当前环境下所有包及精确版本,生成 requirements.txt,用于部署或还原环境。

8️⃣ 同步锁定依赖(高级用法)

uv sync

根据 requirements.txtrequirements.lock 精确安装依赖,保持团队环境一致(类似 pip-sync)。

9️⃣ 查看包信息

uv pip show fastapi

显示某个包的详细信息,包括安装路径、版本、依赖等。

🔟 清理缓存

uv pip cache purge

清空下载缓存,释放磁盘空间

🧪 快速示例:FastAPI 项目初始化

uv venv
uv pip install fastapi uvicorn
uv pip freeze > requirements.txt
uvicorn main:app --reload

✅ 总结

📌 建议

  • uv 设置为默认包管理器,能显著提升开发效率

  • 配合 requirements.txtpyproject.toml 使用效果更佳

  • 可在团队中推广 uv sync 保证依赖一致性