比pip快100倍的Python包安裝工具
簡介
uv是一款開源的Python包安裝工具,GitHub star高達56k,以性能極快著稱,具有以下特性(官方英文原文):
- A single tool to replace
pip,pip-tools,pipx,poetry,pyenv,twine,virtualenv, 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
curlorpip. - ? 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
更多用法請閱讀官方文檔。
參考資料:
所有文章公眾號【測試開發剛哥】首發!
版權申明:本文為博主原創文章,轉載請保留原文鏈接及作者。

浙公網安備 33010602011771號