比pip快100倍的Python包安装工具

简介

uv是一款开源的Python包安装工具,GitHub star高达56k,以性能极快著称,具有以下特性(官方英文原文):

  • A single tool to replace pippip-toolspipxpoetrypyenvtwinevirtualenv, and more.
  • ⚡️ 10-100x faster than pip.
  • ️ Provides comprehensive project management, with a universal lockfile.
  • ❇️ Runs scripts, with support for inline dependency metadata.
  • Installs and manages Python versions.
  • ️ Runs and installs tools published as Python packages.
  • Includes a pip-compatible interface for a performance boost with a familiar CLI.
  • Supports Cargo-style workspaces for scalable projects.
  • Disk-space efficient, with a global cache for dependency deduplication.
  • ⏬ Installable without Rust or Python via curl or pip.
  • ️ Supports macOS, Linux, and Windows.

在Python MCP SDK的介绍中,也出现了We recommend using uv to manage your Python projects的字样,说明uv已经是一款实用性极强的工具。

安装

macOS and Linux

curl -LsSf https://astral.sh/uv/install.sh | sh

Windows

powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

当然也可以通过pip安装:

pip install uv

使用

创建项目:

uv init example
cd example

虚拟环境:

uv venv

执行后会提示:

Creating virtual environment at: .venv
Activate with: source .venv/bin/activate

激活:

source .venv/bin/activate

安装其他包,比如pandas:

uv add pandas

第一次安装可能会慢一点,但也要比pip快很多。第二次基本上就是秒装了,而pip可能还需要多花时间加载。

Python多版本

安装多个Python版本:

uv python install 3.10 3.11 3.12

指定某个版本创建虚拟环境:

uv venv --python 3.12.0

可以创建多个不同版本的虚拟环境,激活某个虚拟环境就会使用相应版本。

如果需要临时切到某个版本,可以在当前目录指定:

uv python pin 3.11
# Pinned `.python-version` to ``3.11

更多用法请阅读官方文档。

参考资料:

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

你可能感兴趣的:(pip,python,开发语言)