uv#
pip vs uv Command Mapping#
| Action | pip / venv | uv (pip interface) | uv (project interface) |
|---|---|---|---|
| Create virtualenv | $ python -m venv .venv | $ uv venv | $ uv init |
| Install package | $ pip install <package> | $ uv pip install <package> | $ uv add <package> |
| Install from requirements | $ pip install -r requirements.txt | $ uv pip install -r requirements.txt | $ uv sync |
| Uninstall package | $ pip uninstall <package> | $ uv pip uninstall <package> | $ uv remove <package> |
| Freeze dependencies | $ pip freeze > requirements.txt | $ uv pip freeze | $ uv lock |
| Sync environment | N/A (pip-sync) | $ uv pip sync requirements.txt | $ uv sync |
| Run script in env | $ source .venv/bin/activate && python <script.py> | $ uv run <script.py> | $ uv run <script.py> |
pip Interface Mode#
uv pip provides a drop-in replacement for standard pip workflows with substantial speedups.
Virtual Environment Management#
- Create a virtual environment:
$ uv venv - Create with a specific Python version:
$ uv venv --python 3.12
Package Management#
- Install packages:
$ uv pip install <package> - Install from
requirements.txt:$ uv pip install -r requirements.txt - Uninstall packages:
$ uv pip uninstall <package>
Lockfile and Synchronization#
- Compile
requirements.intorequirements.txt:$ uv pip compile requirements.in -o requirements.txt - Sync environment exactly to
requirements.txt:$ uv pip sync requirements.txt
Project Management Mode#
uv supports project-level dependency management using pyproject.toml and uv.lock.
Project Initialization#
- Initialize a new project:
$ uv init <project-name>
Managing Dependencies#
- Add dependencies:
$ uv add <package> - Add development dependencies:
$ uv add --dev <package> - Remove dependencies:
$ uv remove <package> - Sync dependencies to environment:
$ uv sync
Running Commands#
uv run executes commands within the managed environment without manual activation (source .venv/bin/activate).
- Run a script:
$ uv run <script.py> - Run a module or CLI:
$ uv run pytest
Python Version Management#
uv downloads and manages Python toolchains automatically without requiring pyenv.
- Install Python versions:
$ uv python install 3.11 3.12 - List installed and available Python versions:
$ uv python list - Pin project Python version:
$ uv python pin 3.12
CLI Tool Execution#
uvx (alias for uv tool run) executes CLI tools in ephemeral virtual environments without installing them globally.
- Run CLI tool ephemerally:
$ uvx ruff check . - Install CLI tool globally:
$ uv tool install ruff
Single-file Script Execution#
Run standalone scripts with inline dependency metadata (PEP 723) or ad-hoc dependencies.
- Run script with temporary dependencies:
$ uv run --with requests <script.py>