■ Introduction to UV (Python Package Manager)
UV is a high-performance Python package manager written in Rust. It replaces traditional
tools like pip, pip-tools, venv, and virtualenv. Developed by Astral.
■ Key Advantages
- Very fast installation and dependency resolution.
- Single tool for installing, locking, and syncing dependencies.
- Compatible with [Link] and [Link].
- Built-in virtual environment manager.
- Lock file support (similar to pip-tools).
- Cross-platform support (Windows, macOS, Linux).
■ Installation
On macOS:
brew install uv
Current version used: 0.7.11. Other OS installation methods available in official
documentation.
■ Traditional Setup with venv
mkdir with_venv && cd with_venv
python3 -m venv venv
source venv/bin/activate
pip install -r [Link]
pip freeze > [Link]
■ Using UV
Initialize a project:
mkdir with_uv && cd with_uv
uv init
This creates files like .gitignore, [Link], and a sample [Link]
■ [Link]
Defines project metadata and dependencies. Replaces [Link], [Link], and
[Link].
[project]
name = "uv-demo"
version = "0.1.0"
authors = [{ name = "John Doe", email = "john@[Link]" }]
description = "A demo UV project"
requires-python = ">=3.12"
dependencies = []
■ Managing Python Versions
uv python list
uv python install 3.12.11
■ Adding and Removing Packages
uv add requests
uv remove requests
■ Running Code
uv run [Link]
■ Viewing Dependency Tree
uv tree
■ Reproducing Environments
Copy [Link] and [Link], then run uv run [Link] to recreate environment.
■ Importing Existing [Link]
uv add -r [Link]
■ Summary of Concepts
Concept Description
[Link] Defines project metadata and dependencies
[Link] Stores exact dependency versions
uv run Executes scripts in managed environments
uv add/remove Installs or uninstalls dependencies
uv tree Displays dependency structure
uv python Manages Python versions
■ Conclusion
UV simplifies Python project management by combining pip, pip-tools, and venv. It offers
fast dependency resolution and standardized environment replication. A modern, fast, and
reliable alternative for Python environment management.