Python 包管理工具 uv

uv 是由 Rust 编写的超快速 Python 包安装器和解析器,由创建了流行的 Rust 包管理器 Cargo 的团队开发。它旨在成为未来 pip 和 pip-tools 的现代替代品。

主要特性

  1. 极快的性能:比 pip 快 10-100 倍
  2. 现代功能:
    • 支持最新的 Python 包标准
    • 内置虚拟环境管理
    • 支持锁定文件
  3. 兼容性:
    • 兼容现有的 pip 和 pip-tools 工作流
    • 支持 requirements.txt 和 pyproject.toml

uv 安装

bash 复制代码
$powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
Downloading uv 0.7.19 (x86_64-pc-windows-msvc)
Installing to C:\Users\user\.local\bin
  uv.exe
  uvx.exe
  uvw.exe
everything's installed!

To add C:\Users\user\.local\bin to your PATH, either restart your shell or run:

    set Path=C:\Users\user\.local\bin;%Path%   (cmd)
    $env:Path = "C:\Users\user\.local\bin;$env:Path"   (powershell)

主要功能

bash 复制代码
uv -h
An extremely fast Python package manager.

Usage: uv [OPTIONS] <COMMAND>

Commands:
  run      Run a command or script
  init     Create a new project
  add      Add dependencies to the project
  remove   Remove dependencies from the project
  version  Read or update the project's version
  sync     Update the project's environment
  lock     Update the project's lockfile
  export   Export the project's lockfile to an alternate format
  tree     Display the project's dependency tree
  tool     Run and install commands provided by Python packages
  python   Manage Python versions and installations
  pip      Manage Python packages with a pip-compatible interface
  venv     Create a virtual environment
  build    Build Python packages into source distributions and wheels
  publish  Upload distributions to an index
  cache    Manage uv's cache
  self     Manage the uv executable
  help     Display documentation for a command

Python 版本管理

bash 复制代码
Commands:
  list       List the available Python installations
  install    Download and install Python versions
  upgrade    Upgrade installed Python versions to the latest supported patch release 
  (requires the `--preview` flag)
  find       Search for a Python installation
  pin        Pin to a specific Python version
  dir        Show the uv Python installation directory
  uninstall  Uninstall Python versions

包安装

bash 复制代码
uv pip install flask  # 安装单个包
uv pip install -r requirements.txt  # 从文件安装

虚拟环境管理

bash 复制代码
uv venv .venv  # 创建虚拟环境
source .venv/bin/activate  # 激活虚拟环境

依赖解析

bash 复制代码
uv pip compile pyproject.toml -o requirements.txt  # 生成锁定文件
uv pip sync requirements.txt  # 同步依赖

uv 目前仍处于积极开发阶段,但已经可以用于生产环境,特别适合需要频繁安装Python包或大型项目的开发者。

相关链接

https://docs.astral.sh/uv/

相关推荐
huluang几秒前
VibeVoice 部署全指南:Windows 下的挑战与完整解决方案
windows·python
AI Echoes11 分钟前
一款为开发者而生的开源全栈LLMOps平台
人工智能·python·langchain·agent
玉木子13 分钟前
机器算法(五)模型选择与调优
人工智能·python·深度学习·算法·机器学习
小菜全41 分钟前
使用Java获取本地PDF文件并解析数据
java·开发语言·python
无边风月-风之羽翼1 小时前
【自记录】Ubuntu20.04下Python自编译
开发语言·python
蒋星熠2 小时前
.NET技术深度解析:现代企业级开发指南
人工智能·python·深度学习·微服务·ai·性能优化·.net
做科研的周师兄2 小时前
【机器学习入门】3.2 ALS算法——从评分矩阵到精准推荐的核心技术
人工智能·python·深度学习·线性代数·算法·机器学习·矩阵
二闹3 小时前
一文搞懂Python装饰器,还能用它给代码加权限锁!
后端·python
励志不掉头发的内向程序员3 小时前
从零开始的python学习——函数(2)
开发语言·python·学习
Gyoku Mint3 小时前
猫猫狐狐的“你今天有点怪怪的”侦察日记
人工智能·python·深度学习·神经网络·自然语言处理·pycharm·数据分析