uv --- replacement of conda + pip (python version + package version install) python版本和包管理集大成者

lightsong / 2024-10-05 / 原文

uv

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

An extremely fast Python package and project manager, written in Rust.

Shows a bar chart with benchmark results.

 

Installing Trio's dependencies with a warm cache.

Highlights

  • 🚀 A single tool to replace pip, pip-tools, pipx, poetry, pyenv, virtualenv, and more.
  • ⚡️ 10-100x faster than pip.
  • 🐍 Installs and manages Python versions.
  • 🛠️ Runs and installs Python applications.
  • ❇️ Runs scripts, with support for inline dependency metadata.
  • 🗂️ Provides comprehensive project management, with a universal lockfile.
  • 🔩 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.

uv is backed by Astral, the creators of Ruff.

 

https://github.com/astral-sh/uv

Python management

uv installs Python and allows quickly switching between versions.

Install multiple Python versions:

$ uv python install 3.10 3.11 3.12
Searching for Python versions matching: Python 3.10
Searching for Python versions matching: Python 3.11
Searching for Python versions matching: Python 3.12
Installed 3 versions in 3.42s
 + cpython-3.10.14-macos-aarch64-none
 + cpython-3.11.9-macos-aarch64-none
 + cpython-3.12.4-macos-aarch64-none
 

Download Python versions as needed:

$ uv venv --python 3.12.0
Using Python 3.12.0
Creating virtual environment at: .venv
Activate with: source .venv/bin/activate

$ uv run --python pypy@3.8 -- python --version
Python 3.8.16 (a9dbdca6fc3286b0addd2240f11d97d8e8de187a, Dec 29 2022, 11:45:30)
[PyPy 7.3.11 with GCC Apple LLVM 13.1.6 (clang-1316.0.21.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>>
 

Use a specific Python version in the current directory:

$ uv python pin pypy@3.11
Pinned `.python-version` to `pypy@3.11`
 

See the Python installation documentation to get started.