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/

相关推荐
不惑_6 小时前
通俗理解感知机(Perceptron)
人工智能·python
潇与上海6 小时前
【Windows任务栏的文件资源管理器打不开”没有与之关联的应用”】
windows
Everybody_up6 小时前
pycharm中编译环境配置
ide·python·pycharm
零小陈上(shouhou6668889)7 小时前
YOLOv8+PyQt5输电线路缺陷检测(目前最全面的类别检测,可以从图像、视频和摄像头三种路径检测)
python·qt·yolo
luoluoal7 小时前
基于python的爬虫的贵州菜价可视化系统(源码+文档)
python·mysql·django·毕业设计·源码
2501_921649497 小时前
股票 API 对接,接入美国纳斯达克交易所(Nasdaq)实现缠论回测
开发语言·后端·python·websocket·金融
2401_841495647 小时前
【LeetCode刷题】打家劫舍
数据结构·python·算法·leetcode·动态规划·数组·传统dp数组
李昊哲小课7 小时前
简化版天气爬虫教程
爬虫·python
3824278277 小时前
python:Ajax爬取电影详情实战
开发语言·python·ajax
天呐草莓7 小时前
集成学习 (ensemble learning)
人工智能·python·深度学习·算法·机器学习·数据挖掘·集成学习