Learn  /  Guides

Modern Python setup with uv: environments, dependencies and scripts

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

Guide6 min readUpdated 30 September 2026
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.

One tool instead of four

pip
uv add, uv sync (or uv pip install)
virtualenv / venv
Created automatically by uv run
pyenv
uv python install
pipx
uvx

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.14     # 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

Check your understanding

1/3Which two files should you commit to Git in a uv project?

2/3What does uv run python report.py do first?

3/3How do you run Ruff without installing it in your project?

Put uv to work: automate a weekly report, or see what's new in Python 3.15 (uv python install 3.15).

Alessandro Ecclesie AgazziWritten by Alessandro Ecclesie Agazzi, analytics engineer in London. Updated 30 September 2026. About me

Found this useful?

New guides and "what's new" explainers on data and AI land here regularly. Follow along on LinkedIn, or share this one with a colleague.