Guide, 6 min read, updated 30 September 2026

Modern Python setup with uv: environments, dependencies and scripts

One fast tool that replaces pip, virtualenv and pyenv for most projects.

Python
All guides and cheat sheets

For years, setting up Python meant juggling pip, virtualenv, pyenv and a requirements.txt that never quite matched production. uv, from Astral, the team behind the Ruff linter, combines those jobs in one very fast tool written in Rust. It has quickly become a popular default for new Python projects.

Install uv

Terminal
# macOS and Linux
curl -LsSf https://astral.sh/uv/install.sh | sh

# or with Homebrew
brew install uv

Install and pin a Python version

Terminal
uv python install 3.13     # downloads a managed Python build
uv python list             # shows installed and available versions

Start a project

Terminal
uv init sales-report
cd sales-report
uv add pandas openpyxl duckdb      # adds to pyproject.toml and updates uv.lock
uv add --dev ruff pytest           # development-only dependencies

This creates a pyproject.toml describing your dependencies and a uv.lock file recording exact versions. Commit both to Git so everyone, including your server, runs the same versions.

Run code without activating anything

Terminal
uv run python report.py    # creates or updates .venv automatically, then runs
uv run pytest
uv sync                    # install exactly what uv.lock specifies

Single-file scripts with inline dependencies

For a quick automation, you can declare dependencies at the top of the script itself, following the inline script metadata standard (PEP 723).

Python
# /// script
# requires-python = ">=3.12"
# dependencies = ["pandas", "openpyxl"]
# ///
import pandas as pd

df = pd.read_excel("sales.xlsx")
print(df.groupby("region")["amount"].sum())
Terminal
uv run report.py    # uv installs pandas and openpyxl in an isolated environment first

Run tools without installing them

Terminal
uvx ruff check .    # lint your code
uvx ruff format .   # format it

Coming from requirements.txt

Terminal
uv add -r requirements.txt                 # import an existing list into a project
uv export --format requirements-txt > requirements.txt   # produce one for other tools

uv also offers a pip-compatible interface, such as uv pip install pandas, so it drops into existing workflows easily.

Written by Alessandro Ecclesie Agazzi, freelance analytics engineer in London. Updated 30 September 2026.