ENVIRONMENTS · INDEXES · RANGES · RESOLVER · LOCKFILE · CACHE · BUILDS · PYTHONS · TOOLS · WORKSPACES

uv:
how Python dependencies are resolved, locked and installed

uv is one program that sets up and runs Python projects. It installs Python, creates the project’s environment, chooses a version of every package your code needs, writes those choices to a lockfile and installs them. Before uv, pip, venv, pip-tools, pipx and pyenv each did one of those jobs.

A finance team runs fx-report every night. It downloads the day’s exchange rates through the company’s own rates-client library, turns them into a table with pandas, and posts a report with requests. Two engineers use Macs, one uses Windows, and the job runs in a Linux container. All four need the same packages, and the chapters follow how uv makes that true.

Here is every part this tutorial covers. Most boxes won’t mean much yet; each chapter explains one of them.

MapSolid outlines are folders and the uv process; the dashed one is the internet. Arrows follow data from the index to the environment.

You need to know how to run a command in a terminal and what pip install does from the outside. The tutorial teaches uv 0.13.10 beside pip 26.3, checked against their source on 30 November 2026; package versions are PyPI’s on that day. The finance team, its company index, rates-client and every timing are made up. Tap any figure to open it full screen and zoom. Dotted terms are tappable.

Where packages live: the virtual environment

You have a laptop with Python 3.14 and a new project, fx-report, that needs requests and pandas. A plain pip install puts them wherever that Python keeps its packages, shared by every project on the machine, and on many Linux systems it refuses outright. Each project needs a folder of its own packages and a way for Python to find it. Here that folder is made from the Python 3.14 already on the laptop; chapter 08 explains where uv finds or fetches one. What is a virtual environment, and how does uv choose which one to install into?

STEP 01 / 04

THE MAP SO FAR

Fig 1.1The accent folder is the environment; faint parts arrive in later chapters.

A virtual environment is a folder that holds a link to one Python interpreter and a private site-packages directory, where installed packages go. uv makes one per project, called .venv, inside the project folder.

This map shows every part uv works with, and each chapter adds one. Faint parts belong to later chapters. All of them exist to fill .venv correctly: it is where uv’s work ends.

STEP 02 / 04

AN ENVIRONMENT IS A FOLDER AND ONE CONFIG FILE

Fig 1.2The accent file is pyvenv.cfg: its home line names the base Python, and false hides that Python’s packages.

.venv/bin/python is a symlink to the base interpreter, here uv’s own Python 3.14; python3 and python3.14 link to it. At startup Python looks for pyvenv.cfg next to its executable or one folder up. When it finds one, sys.prefix becomes .venv and imports come from its site-packages, while sys.base_prefix still points at the base install.

So running .venv/bin/python uses the environment with no activation. source .venv/bin/activate does one thing: it puts .venv/bin first on PATH, so a bare python in your shell means this one.

uv’s pyvenv.cfg adds a uv = 0.13.10 line and writes version_info, where CPython’s own venv module writes version. uv also puts a .gitignore containing * in the folder, so git never picks it up.

FX-REPORT/.VENV/PYVENV.CFG, AS UV WRITES IT
home = /Users/you/.local/share/uv/python/cpython-3.14-macos-aarch64-none/bin
implementation = CPython
uv = 0.13.10
version_info = 3.14
include-system-site-packages = false
prompt = fx-report
STEP 03 / 04

pip INSTALLS WHERE ITS PYTHON LIVES; uv LOOKS FOR AN ENVIRONMENT

Fig 1.3Read the uv rows top down: uv stops at the first match, the accent .venv, and refuses when nothing matches.

pip installs into the interpreter that runs it. Run with the system Python, pip install writes into the system’s own packages. On Debian, Ubuntu and Homebrew Python it stops instead with error: externally-managed-environment: that Python carries a marker file, defined by PEP 668, saying the operating system’s package manager owns it.

uv pip install looks for a target instead, in order: the VIRTUAL_ENV variable that activation sets, CONDA_PREFIX for an active conda environment, then a .venv in the current folder or any parent. With none of them it refuses, unless you pass --system. Activation is optional, because uv finds .venv itself.

UV FINDS .VENV WITHOUT ACTIVATION (TIMINGS ILLUSTRATIVE)
$ cd fx-report
$ uv venv
Using CPython 3.14.10
Creating virtual environment at: .venv
Activate with: source .venv/bin/activate
$ uv pip install requests      # no activation: uv finds .venv itself
Resolved 5 packages in 212ms
Prepared 5 packages in 96ms
Installed 5 packages in 7ms
 + certifi==2026.11.20
 + charset-normalizer==3.5.3
 + idna==3.20
 + requests==2.34.2
 + urllib3==2.8.0
$ cd /tmp && uv pip install requests
error: No virtual environment found; run `uv venv` to create an environment, or pass `--system` to install into a non-virtual environment
STEP 04 / 04

uv LIVES OUTSIDE EVERY ENVIRONMENT

Fig 1.4The accent column has one program and three environments; pip’s column has a copy of pip in each.

pip is a Python package. Each environment holds its own copy in site-packages, and it runs on that environment’s interpreter. uv is one compiled binary that lives outside every environment and writes into whichever .venv it is pointed at.

So uv venv puts no pip in the new environment (--seed adds one), and python -m pip inside a uv environment fails with No module named pip. Use uv pip install instead. One uv binary serves every project and every Python version on the machine.

COMMON QUESTIONS

Do I have to activate .venv to use it?
No. uv run uses it directly, and .venv/bin/python works without activation. Activate only if you want a bare python in your shell to mean the project’s interpreter.
Should .venv go into git?
No. uv writes a .gitignore containing * inside it. Commit pyproject.toml and uv.lock; anyone can rebuild .venv from those with one command.
Can I use conda environments with uv?
uv pip installs into an active conda environment, because it reads CONDA_PREFIX. Project commands such as uv sync and uv run always use the project’s own .venv.

WHAT YOU NOW KNOW

  • A virtual environment is a folder with pyvenv.cfg, a symlink to one interpreter, and its own site-packages.
  • pip installs into whichever Python runs it; uv pip finds VIRTUAL_ENV, CONDA_PREFIX or .venv, and refuses the system Python.
  • uv is one program outside every environment, so a uv .venv contains no pip.
DEEP DIVE: how site finds the environment, relocatable environments, system site-packages, a short history of uv

How site finds the environment

PEP 405 defines the mechanism. Before your code runs, Python looks for pyvenv.cfg in the folder of the executable it was started as, then one folder up. If it finds one, the site module sets sys.prefix and sys.exec_prefix to that folder and adds its site-packages to sys.path. The home key says where the base install is, and the standard library still comes from there.

With include-system-site-packages = false, the base install’s own site-packages stays off sys.path, so a package installed there by hand is invisible inside the environment. Nothing in the base install is copied; the environment only points at it.

Relocatable environments

uv venv --relocatable writes relative paths into the scripts in bin/ and adds a relocatable line to pyvenv.cfg. The folder can then move, as long as the base Python stays where home says. That is worth it when one stage of a container build fills .venv and a later stage copies it into the final image under another path.

System site-packages

uv venv --system-site-packages writes include-system-site-packages = true, so imports fall back to the base Python’s own packages. That brings back the sharing problem: code works on your machine because of a package the base install happens to hold, and fails everywhere else. On 64-bit Unix systems other than macOS, uv also adds lib64 as a symlink to lib, for tools that look there.

A short history of uv

Astral released uv 0.1.0 on 15 February 2024 as a fast replacement for pip’s install commands. 0.3.0, on 20 August 2024, added projects, uv.lock, uv run, tools and Python management. 0.13.0 made Python 3.15 the default, and this tutorial teaches 0.13.10.

On 19 March 2026 Astral announced that it had “entered into an agreement to join OpenAI as part of the Codex team”. uv’s version number still starts with 0.

ERRORS THIS CHAPTER EXPLAINS

error: externally-managed-environment
pip was run with a system Python that the operating system’s package manager owns
make an environment with uv venv and install there
error: No virtual environment found
uv pip found no VIRTUAL_ENV, CONDA_PREFIX or .venv
run uv venv, or pass --system if you mean the system Python
No module named pip
a uv environment has no pip in it
use uv pip install, or make the environment with uv venv --seed

Where packages come from: the index, wheels and sdists

fx-report has a .venv, and it is empty. Somewhere there must be a list of every requests release and the files for each, and fx-report needs public packages from PyPI as well as the company’s own rates-client. pandas 3.1.1 alone has 57 ready-built files on PyPI, one for each operating system, CPU and Python version it supports. How does an installer find a file that runs on your machine?

STEP 01 / 04

THE MAP SO FAR

Fig 2.1The accent box asks; the two accent servers answer with lists of files.

A package index is a web server that lists every file of every release of each package. PyPI is the public one, and companies run their own. Inside uv, the index client fetches those lists and then the files.

This chapter adds three parts to the map: PyPI, the company’s fxco index, and the index client between them and the project. Like everything about fx-report’s company, the fxco index is illustrative.

STEP 02 / 04

AN INDEX PAGE LISTS EVERY FILE OF EVERY VERSION

Fig 2.2Each row is one file; the accent row is the wheel uv will use, with its size and hash.

uv requests pypi.org/simple/requests/ and asks for the JSON form of the Simple API; PyPI answers with api-version: 1.4. Each file entry carries its filename, URL and sha256 hash, the Python range it supports, whether a separate metadata file exists, its size, its upload time and whether it was yanked.

An index serves two kinds of file. A wheel is a ready-built zip that an installer only unpacks; an sdist is source code that must be built first. requests 2.34.2 has one of each: a 73,075-byte wheel and a 142,856-byte sdist.

PyPI marks the page fresh for 600 seconds, so a uv with a warm cache asks again at most every 10 minutes. Between those, it reads the page from disk.

PYPI’S JSON PAGE FOR REQUESTS, TRIMMED TO ONE FILE
{
  "meta": { "api-version": "1.4" },
  "name": "requests",
  "files": [
    {
      "filename": "requests-2.34.2-py3-none-any.whl",
      "url": "https://files.pythonhosted.org/packages/a0/f4/…/requests-2.34.2-py3-none-any.whl",
      "hashes": { "sha256": "2a0d60c172f83ac6ab31e4554906c0f3b3588d37b5cb939b1c061f4907e278e0" },
      "requires-python": ">=3.10",
      "core-metadata": { "sha256": "8c384ba3e979480faae2859d3c5e6c1276dd2c3616e322e124d52c8cfc556f27" },
      "size": 73075,
      "upload-time": "2026-05-14T19:25:26.443000Z",
      "yanked": false
    }
  ]
}
STEP 03 / 04

A WHEEL’S NAME SAYS WHERE IT RUNS

Fig 2.3Rows run in uv’s preference order; the accent row is the first one this Mac can run.

A wheel’s filename is name-version-python-abi-platform.whl: the Python it needs, the ABI its compiled code expects, and the platform tag for the operating system and CPU. numpy 2.5.5 has 65 wheels and one sdist, because compiled code runs only where it was built. When no wheel fits, uv falls back to the sdist; chapter 07 builds one.

uv lists the tags this machine supports, most specific first: the exact cp314 build, then abi3, then none, then the pure py3-none-any; within each, the newest platform first. On macOS 15, numpy’s macosx_14_0_arm64 wheel (5.5 MB) beats the macosx_11_0_arm64 one (10.8 MB).

STEP 04 / 04

ONE INDEX PER PACKAGE NAME

Fig 2.4Same two indexes, two tools; the accent path is pip taking the stranger’s upload.

fx-report adds the fxco index with explicit = true and pins rates-client to it in [tool.uv.sources]. Explicit means uv uses fxco only for packages pinned to it, so uv asks it for rates-client (versions 1.4.0, 2.0.0, 2.1.0, all illustrative) and nothing else.

Even without the pin, uv’s default strategy, first-index, takes a name only from the first index that has it. pip merges candidates from every index and picks the highest version anywhere. If someone uploads rates-client 99.0.0 to PyPI, pip with --extra-index-url installs it. That attack is dependency confusion.

PYPROJECT.TOML: THE COMPANY INDEX, FOR ONE PACKAGE
# pyproject.toml
[[tool.uv.index]]
name = "fxco"
url = "https://packages.fxco.example/simple/"
explicit = true          # used only by packages pinned to it below

[tool.uv.sources]
rates-client = { index = "fxco" }

COMMON QUESTIONS

Is pypi.org the only public index?
It is the default one. Mirrors and company proxies such as Artifactory and devpi serve the same Simple API, and uv talks to any of them through [[tool.uv.index]].
What does “yanked” mean?
The maintainer withdrew the version. Installers skip it unless a requirement pins exactly that version with ==.
Why does one numpy release have 65 files?
Compiled code runs only on the CPU, operating system and Python build it was compiled for, so numpy publishes one wheel per combination.

WHAT YOU NOW KNOW

  • The Simple API lists each file with its URL, sha256, size, upload time and Python range; uv reads its JSON form.
  • A wheel’s filename names the Python, ABI and platform; uv picks the most specific one this machine runs.
  • uv takes each name from the first index that has it, so a PyPI upload can’t replace rates-client from fxco.
DEEP DIVE: HTML and JSON Simple API, manylinux and musllinux, abi3 and free-threading, credentials, hashes uv checks

HTML and JSON Simple API

The Simple API started as a page of HTML links (PEP 503). PEP 691 added a JSON form with the same content, PEP 700 added each file’s size and upload time, PEP 714 named the core-metadata field, and PEP 740 adds provenance, a signed record of where a file was built. uv’s Accept header asks for application/vnd.pypi.simple.v1+json first and HTML at lower priority, and it reads whichever the index returns.

manylinux and musllinux

A Linux wheel names the oldest glibc it needs: manylinux_2_27_x86_64 runs on any x86-64 Linux with glibc 2.27 or later. A wheel can carry two platform tags joined by a dot when it satisfies both; numpy’s Linux wheel is tagged manylinux_2_27_x86_64.manylinux_2_28_x86_64. musllinux tags do the same for systems built on musl, such as Alpine.

abi3 and free-threading

Most compiled wheels target one CPython minor version, such as cp314. A wheel tagged abi3 uses only CPython’s stable ABI, so one build runs on its own version and every later one. Free-threaded CPython builds, which run without the global interpreter lock, need wheels of their own, tagged cp314t or abi3t. pandas 3.1.1 ships cp314t and cp315t wheels.

Credentials for private indexes

uv auth login stores a credential for an index. By default uv keeps it in plain text in ~/.local/share/uv/credentials/credentials.toml; the system keychain backend is still a preview feature, and uv can also ask the keyring package. Never write a token into an index URL in pyproject.toml: that file is committed, so the token ends up in git.

Hashes uv checks, and one it doesn’t

uv checks every downloaded file against the sha256 the index lists, and against uv.lock when the project has one. Inside a wheel, the RECORD file lists a hash for every file the wheel holds. Neither uv nor pip validates those hashes, as the text of PEP 815 says; uv only checks that RECORD lists the right files. The supply chain tutorial’s wheel chapter shows what that leaves open.

What you ask for: ranges, metadata and the tree

uv can now find and fetch any file. It still needs to know what fx-report wants, and “requests” isn’t one file: it is many versions, and each version needs packages of its own. You write a few lines, and the packages those lines pull in decide most of what lands in .venv. How do four lines in a file become fifteen installed packages?

STEP 01 / 04

THE MAP SO FAR

Fig 3.1The accent file is the one you edit: it says what the project needs.

pyproject.toml is the project’s own description: its name, the Python versions it supports and what it depends on. uv reads it and never asks you for a list of exact versions. This chapter adds it to the project folder.

The other half of the answer isn’t on the map: every package on PyPI carries its own list of what it needs, inside each wheel. Step 3 shows how uv reads that list without downloading the wheel.

STEP 02 / 04

YOU WRITE RANGES, NOT VERSIONS

Fig 3.2Each row is one way to write the line; ticks show which real releases it allows.

pyproject.toml is a TOML file: sections of key = value lines. uv add requests writes requests>=2.34.2 into its dependencies, a version specifier with the newest version uv found as its lower bound. It also locks and installs; chapters 05 and 06 explain those two steps. --bounds writes a major, minor or exact bound instead.

PEP 440 defines the operators: >=, <, ==, !=, === and ~=, the compatible release: ~=2.34 means 2.34 or later, below 3. uv add --dev pytest writes pytest>=9.2.0 to [dependency-groups] dev, a dependency group that is never published with the package. --optional writes an extra, which is.

FX-REPORT’S PYPROJECT.TOML AFTER UV ADD
[project]
name = "fx-report"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = [
    "requests>=2.34.2",
    "pandas>=3.1.1",
    "rates-client>=2.0",
]

[project.scripts]
fx-report = "fx_report:main"

[dependency-groups]
dev = ["pytest>=9.2.0"]

[build-system]
requires = ["uv_build>=0.13.10,<0.14"]
build-backend = "uv_build"
STEP 03 / 04

EVERY PACKAGE LISTS WHAT IT NEEDS

Fig 3.3Follow 1 to 3; the accent first try answers without touching the 11.3 MB wheel.

Each wheel contains a METADATA file. Its Requires-Dist lines are that package’s own ranges, some with an environment marker such as ; sys_platform == "win32", which limits where the line applies. pandas 3.1.1 needs numpy and python-dateutil everywhere, and tzdata only on Windows and Emscripten.

To read those lines without downloading the wheel, uv tries three things in order. First, the separate .metadata file the index serves beside the wheel (PEP 658). Next, a range request, an HTTP request for only some bytes of a file, to read the zip’s directory and then the METADATA entry. Last, the whole file.

uv reads one version’s metadata once for all its wheels, so numpy’s 65 files cost one request. pip has used PEP 658 files since pip 22.3; without one, it downloads the whole wheel.

PANDAS 3.1.1’S METADATA, TRIMMED TO ITS REQUIREMENTS
Name: pandas
Version: 3.1.1
Requires-Python: >=3.11
Requires-Dist: numpy>=2.0.2; python_version < "3.14"
Requires-Dist: numpy>=2.3.3; python_version >= "3.14"
Requires-Dist: python-dateutil>=2.9.0
Requires-Dist: tzdata; sys_platform == "win32"
Requires-Dist: tzdata; sys_platform == "emscripten"
STEP 04 / 04

FOUR LINES PULL IN FIFTEEN PACKAGES

Fig 3.4Your four lines sit on top; every accent box below arrived on its own.

fx-report declares requests, pandas, rates-client and pytest. Their own requirements add certifi, charset-normalizer, idna and urllib3 (requests); numpy and python-dateutil, which adds tzdata (pandas); and iniconfig, packaging, pluggy and pygments (pytest). rates-client needs requests and pandas, which are already there.

That makes 15 packages on macOS and Linux, and 16 on Windows, where pytest also needs colorama (sys_platform == 'win32'). The ones you didn’t write are transitive dependencies.

uv tree prints the tree. (*) marks a package whose subtree was already printed, and by default it shows only this platform’s packages, so colorama is missing on a Mac.

UV TREE ON A MAC (TIMING ILLUSTRATIVE)
$ uv tree
Resolved 17 packages in 4ms
fx-report v0.1.0
├── pandas v3.1.1
│   ├── numpy v2.5.5
│   └── python-dateutil v4.0.0
│       └── tzdata v2026.6
├── rates-client v2.0.0
│   ├── pandas v3.1.1 (*)
│   └── requests v2.34.2
│       ├── certifi v2026.11.20
│       ├── charset-normalizer v3.5.3
│       ├── idna v3.20
│       └── urllib3 v2.8.0
├── requests v2.34.2 (*)
└── pytest v9.2.0 (group: dev)
    ├── iniconfig v2.3.1
    ├── packaging v26.4
    ├── pluggy v1.7.0
    └── pygments v2.21.0
(*) Package tree already displayed

COMMON QUESTIONS

Why does uv add write >= and not ==?
An exact pin stops the resolver from choosing anything else that fits, which hurts most in a library. The lockfile pins exact versions; pyproject.toml keeps ranges.
Should I add upper bounds like <3?
Only when you know a release breaks you. An upper bound can make two packages impossible to install together.
Where are dev dependencies in pip?
Teams kept a requirements-dev.txt. PEP 735 standardised [dependency-groups], and pip can install one with --group.

WHAT YOU NOW KNOW

  • uv add requests writes requests>=2.34.2: a range in pyproject.toml, never an exact version.
  • Each package’s Requires-Dist lines add its own ranges, read from a PEP 658 metadata file when the index has one.
  • Four declared lines become 15 packages on macOS and 16 on Windows, where a marker adds colorama.
DEEP DIVE: PEP 440 corner cases, markers and extras, indexes without metadata files, reading the tree

PEP 440 corner cases

~=2.34 means >=2.34, ==2.*, while ~=2.34.0 means >=2.34.0, ==2.34.*: one more digit holds one more level still. A local version such as 2.5.0+cpu matches ==2.5.0, and PyPI refuses uploads that carry one.

Pre-releases such as 2.35.0rc1 are skipped unless you name one or nothing else fits. A post-release such as 2.34.2.post1 sorts after 2.34.2. === compares the version as a plain string and is rarely the right choice.

Markers and extras

A marker can test python_version, sys_platform, platform_machine, implementation_name and a few more. Inside a package, a line ending in ; extra == "socks" applies only when someone installs requests[socks].

pytest requires tomli with the marker python_version < "3.11". fx-report declares requires-python = ">=3.12", so that line can never apply, and uv leaves tomli out of the tree and the lock.

When an index has no metadata files

Many private indexes serve no .metadata files. uv then requests the last 16 KiB of the wheel, where a zip keeps its directory of entries, finds METADATA and fetches only those bytes. If the server ignores range requests, uv logs Range requests not supported for `…`; streaming wheel and reads the whole file. pip’s equivalent, --use-feature=fast-deps, is still experimental in pip 26.3.

Reading the tree

uv tree --invert --package tzdata turns the tree upside down: it prints tzdata, then python-dateutil, which needs it, then pandas and fx-report. That answers why something is installed. --depth 1 shows only what you declared, --outdated adds the newest version on the index beside each package, and --universal shows every platform’s packages, colorama included.

Choosing versions: the resolver

fx-report declares three ranges, and every package they pull in brings ranges of its own. Something has to pick exactly one version of each package so that every range in the whole tree holds at once, and say clearly why when that is impossible. That job is a search, and in the worst case a very hard one. How does uv choose one version of everything, and what happens when ranges clash?

STEP 01 / 04

THE MAP SO FAR

Fig 4.1The accent box reads ranges from pyproject.toml and asks the index client for versions; nothing reaches .venv yet.

The resolver takes the ranges from pyproject.toml, asks the index client which versions exist and what each one requires, and returns one version per package. Its answer is a list of name and version pairs; installing them is a later step.

uv’s resolver uses PubGrub, an algorithm designed for package managers. pip uses a different one, a library called resolvelib. This chapter adds the resolver and its two arrows: ranges in from pyproject.toml, versions and metadata back and forth with the index client.

STEP 02 / 04

CHOOSING VERSIONS IS A HARD SEARCH

Fig 4.2The top table is the order uv decides packages in; the accent row is the version it tries first.

Picking versions that satisfy every range is NP-complete. Any yes-or-no logic puzzle, the kind called SAT, can be written as a set of packages whose versions are the choices, so no algorithm is fast on every input. In practice most resolutions never go back on a choice, and the slowest part of uv’s resolver is loading metadata.

uv decides packages in a fixed order: the project and URL requirements, then exact == pins, then packages that have conflicted often, then the rest in the order first seen. After 5 conflicts between two packages, uv swaps their order.

For each package it tries the highest version first, unless uv.lock or .venv already has one that fits every range. Then it keeps that one, which is why locking again rarely moves anything.

STEP 03 / 04

A CONFLICT BECOMES A RULE uv KEEPS

Fig 4.3Rows are the resolver’s notes in order; the accent row is the rule it learned from the clash.

Walk through fx-report, whose rates-client versions are illustrative. uv decides requests 2.34.2, then pandas 3.1.1, then rates-client 2.1.0, the highest version in rates-client>=2.0. But rates-client 2.1.0 requires pandas<3, and pandas 3.1.1 is already chosen. Each choice uv makes is a decision; each fact a rule forces is a derivation.

PubGrub stores the clash as an incompatibility: rates-client 2.1.0 and pandas>=3.1.1 can’t both be chosen. It jumps back to the level where pandas was decided and derives “not rates-client 2.1.0” from the rule. Then it tries rates-client 2.0.0, which needs pandas>=2.2 and fits. The rule stays for the rest of the solve, so uv never tries that pair again.

pip’s resolvelib uses backtracking: it undoes choices and tries older candidates until a set fits, and it gives up after 200,000 rounds.

STEP 04 / 04

AN ERROR THAT EXPLAINS ITSELF

Fig 4.4Read top to bottom: two facts make a rule, and your own requirement closes it.

Now suppose fx-report asks for rates-client>=2.1. Version 2.1.0 is the only one from 2.1 up, and it needs pandas<3, so no answer exists. uv walks its learned rules back to your own requirements and prints them as one argument. Since uv 0.12.14 the message uses error:, cause: and hint: labels.

Read its cause: line as a proof. “Because only rates-client<=2.1.0 is available and rates-client==2.1.0 depends on pandas<3”, uv concludes that every allowed rates-client does. “And because your project depends on pandas>=3.1.1 and rates-client>=2.1”, the requirements are unsatisfiable.

pip reports the same requirements differently. Under “The conflict is caused by” it names the two lines that clash, pandas>=3.1.1 from you and rates-client 2.1.0’s pandas<3, and suggests loosening a range.

UV LOCK WITH RATES-CLIENT>=2.1 (ILLUSTRATIVE)
$ uv lock
error: No solution found when resolving dependencies
  cause: Because only rates-client<=2.1.0 is available and rates-client==2.1.0 depends on pandas<3, we can conclude that rates-client>=2.1.0 depends on pandas<3.
         And because your project depends on pandas>=3.1.1 and rates-client>=2.1, we can conclude that your project's requirements are unsatisfiable.
PIP WITH THE SAME REQUIREMENTS (TRIMMED)
$ pip install -r requirements.txt
ERROR: Cannot install -r requirements.txt (line 3) and pandas>=3.1.1 because these package versions have conflicting dependencies.

The conflict is caused by:
    The user requested pandas>=3.1.1
    rates-client 2.1.0 depends on pandas<3

To fix this you could try to:
1. loosen the range of package versions you've specified
2. remove package versions to allow pip to attempt to solve the dependency conflict

ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts

COMMON QUESTIONS

Does uv always pick the same versions as pip?
Usually, since both prefer the newest version that fits. They decide packages in different orders, so when several answers exist they can differ. A lockfile removes the question.
Can I make uv pick the oldest versions?
--resolution lowest picks the lowest allowed version everywhere, and lowest-direct only for your own dependencies. Libraries use them to test that their lower bounds really work.
Why did uv take a pre-release?
Since uv 0.12.0 the default is if-necessary: a pre-release is chosen only when no stable version satisfies a range, even one deep in the tree.

WHAT YOU NOW KNOW

  • Choosing versions is NP-complete, but uv decides pins and often-conflicting packages first, so most solves never go back on a choice.
  • The clash between rates-client 2.1.0 and pandas 3.1.1 became a rule, and uv chose rates-client 2.0.0.
  • With rates-client>=2.1 there is no answer, and uv’s error spells out why in three steps.
DEEP DIVE: PubGrub step by step, prefetching, pip’s resolvelib, strategies and cooldowns

PubGrub step by step

PubGrub was designed by Natalie Weizenbaum for Dart’s package manager, pub, whose solver.md explains it in full. It keeps a partial solution, the list of decisions and derivations so far, and a set of incompatibilities. Unit propagation checks every incompatibility after each change: if all its terms but one hold, the last one must be false, and that becomes a derivation.

When an incompatibility is fully satisfied, conflict resolution combines it with the incompatibility that caused its most recent term, until the result points at one earlier decision. PubGrub jumps straight back to that level (backjumping), not one step at a time. uv’s docs give a small case: if a 2 needs c 1 and b 2 needs c 2, the solver learns {a 2, b 2} and never pairs them again.

The hardness result is old. Russ Cox’s “Version SAT” (2016) writes any 3-SAT formula as packages and versions, so a fast resolver for every input would solve SAT too. uv’s own docs call resolution “equivalent to the SAT problem and thereby NP-complete”.

Prefetching

uv’s resolver runs on its own thread and sends its metadata requests through a channel that holds 300 requests. When it chooses a version, it asks for the metadata of that version’s dependencies at once, before it needs them. When it has tried 5, 10 and 20 versions of one package, it fetches up to 50 older versions in a batch, because it will probably keep walking down. Source archives are never prefetched: their metadata may need a build.

pip’s resolvelib

pip’s resolver has been resolvelib since pip 20.3. It picks the next package by preference: URL requirements, then == pins, then upper-bounded ranges, then the order you listed them. It prefers what is already installed, and --upgrade-strategy only-if-needed (the default) leaves installed dependencies alone unless a range forces them; eager upgrades them too.

On a conflict it backtracks: it undoes choices and tries older candidates. Each attempt is a round, and after 200,000 rounds it raises ResolutionTooDeep. Its conflict report names the clashing requirements, not the chain of reasons that joins them.

Strategies and cooldowns

--resolution takes highest (the default), lowest or lowest-direct. --prerelease takes disallow, allow, if-necessary (the default) or explicit, which allows a pre-release only for a package whose own range names one.

exclude-newer ignores every file uploaded after a date. Since uv 0.9.17 it also takes a duration such as "7 days", which works as a cooldown: a release must be a week old before uv will choose it, so a malicious upload has time to be found and removed. The supply chain tutorial’s lock chapter shows why that week matters.

ERRORS THIS CHAPTER EXPLAINS

No solution found when resolving dependencies
ranges somewhere in the tree can’t all hold at once
read the cause: lines down to “your project depends on”, then loosen that range or the parent’s
Dependency resolution exceeded maximum depth
pip’s resolvelib hit its limit of 200,000 rounds
add lower bounds to loose requirements so fewer old versions are candidates

Writing the answer down: uv.lock

The resolver found an answer on one Mac, on one day. Run it next month and PyPI has new releases; run it on the Windows laptop and colorama joins the tree. The team needs the answer written down once, for every machine, and checked against pyproject.toml before anyone installs from it. What does the lockfile record, and how does uv know it is still true?

STEP 01 / 05

THE MAP SO FAR

Fig 5.1The accent file is uv.lock, written by the resolver and committed beside pyproject.toml.

uv.lock is a lockfile the resolver writes next to pyproject.toml: the exact version of every package, the index it came from and the hash of every file the project may install. You commit it, and every machine installs from it.

This chapter adds the lockfile and the resolver’s arrow into it. pyproject.toml still says what you accept; uv.lock says what you got, so the answer from chapter 04 is computed once and reused.

STEP 02 / 05

ONE LOCK FOR EVERY PLATFORM

Fig 5.2Same project, two records; the accent row is colorama, the Windows-only package only the lock keeps.

uv lock resolves once for every operating system and every Python in requires-python, a universal resolution. fx-report’s lock has 17 entries, including colorama with its Windows marker, even though the Mac never installs it. Files no supported platform can use are left out.

pip freeze lists what is installed on this machine: 15 packages with exact versions, but no hashes, no colorama and nothing for another Python. uv pip compile works per platform by default, like pip-tools; --universal writes one file for all of them.

STEP 03 / 05

WHAT ONE LOCK ENTRY RECORDS

Fig 5.3One row per field; the accent row is the hash every install of requests must match.

The file opens with version = 1, revision = 5 and requires-python = ">=3.12". Each [[package]] table then gives a name, a version, a source such as registry = "https://pypi.org/simple", its dependencies by name, and every file: the sdist and each wheel with its URL, sha256, size and upload time.

fx-report’s own entry records the ranges it was locked from, under [package.metadata]. Step 5 uses them. uv.lock is uv’s own format; uv export --format pylock.toml writes pylock.toml, the standard lockfile format from PEP 751, which pip can install from as an experimental feature.

UV.LOCK: THE HEADER AND THE REQUESTS ENTRY (URLS SHORTENED)
version = 1
revision = 5
requires-python = ">=3.12"

[[package]]
name = "requests"
version = "2.34.2"
source = { registry = "https://pypi.org/simple" }
dependencies = [
    { name = "certifi" },
    { name = "charset-normalizer" },
    { name = "idna" },
    { name = "urllib3" },
]
sdist = { url = "https://files.pythonhosted.org/…/requests-2.34.2.tar.gz", hash = "sha256:f288924cae4e29463698d6d60bc6a4da69c89185ad1e0bcc4104f584e960b9ed", size = 142856, upload-time = "2026-05-14T19:25:27.735Z" }
wheels = [
    { url = "https://files.pythonhosted.org/…/requests-2.34.2-py3-none-any.whl", hash = "sha256:2a0d60c172f83ac6ab31e4554906c0f3b3588d37b5cb939b1c061f4907e278e0", size = 73075, upload-time = "2026-05-14T19:25:26.443Z" },
]
STEP 04 / 05

A WIDER PYTHON RANGE SPLITS THE LOCK

Fig 5.4The accent slice is the fork uv added when the range reached Python 3.11.

The team lowers requires-python to ">=3.11" for an old reporting server, an illustrative one, that runs Python 3.11. numpy 2.5.5 needs Python 3.12 or later, so no single numpy fits the whole range.

uv makes a fork: it solves Python 3.11 on its own, choosing numpy 2.4.6, the newest release that still runs there, and keeps numpy 2.5.5 for 3.12 and later. The lock holds both numpy entries, and pandas’ dependency on numpy gets one line per version, each with a Python marker. Every machine installs the one for its interpreter.

UV.LOCK AFTER THE CHANGE: TWO NUMPY ENTRIES (ABRIDGED)
[[package]]
name = "numpy"
version = "2.4.6"
source = { registry = "https://pypi.org/simple" }
# … its sdist and wheels

[[package]]
name = "numpy"
version = "2.5.5"
source = { registry = "https://pypi.org/simple" }
# … its sdist and wheels

[[package]]
name = "pandas"
version = "3.1.1"
source = { registry = "https://pypi.org/simple" }
dependencies = [
    { name = "numpy", version = "2.4.6", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.12'" },
    { name = "numpy", version = "2.5.5", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.12'" },
    { name = "python-dateutil" },
]
STEP 05 / 05

IS THE LOCK STILL TRUE?

Fig 5.5Read each change across; the accent row shows that a new release changes nothing until you ask.

Before uv run or uv sync installs anything, uv checks the lock against pyproject.toml: the ranges under [package.metadata], requires-python, groups, indexes and sources. If they still match, it doesn’t resolve again. If not, the lock is stale, and uv locks again, keeping the old versions wherever they still fit.

--locked turns a stale lock into an error, and --frozen skips the check. Tighten pandas>=3.1.1 to pandas>=3.1.1, <3.2 and pandas 3.1.1 still fits, but the recorded range changed, so --locked fails and its cause: line names the change. Upgrades happen only when you ask for them, with uv lock --upgrade-package pandas.

A TIGHTER PANDAS RANGE, CHECKED
$ uv sync --locked
Resolved 17 packages in 12ms
error: The lockfile at `uv.lock` needs to be updated, but `--locked` was provided.
  cause: Requirements for `fx-report==0.1.0` changed from `pandas>=3.1.1` to `pandas>=3.1.1, <3.2`

hint: To update the lockfile, run `uv lock`.

COMMON QUESTIONS

Should a library commit uv.lock?
Yes, for its own tests and CI. People who install the library never see it: the published package carries only the ranges.
Can another tool read uv.lock?
No, it is uv’s own format. Export pylock.toml (PEP 751) or a requirements.txt with hashes for tools that need a standard file.
How do I upgrade one package?
uv lock --upgrade-package pandas resolves again and lets only pandas, and whatever it forces, move. --upgrade lets everything move.

WHAT YOU NOW KNOW

  • uv.lock holds 17 entries for every platform, including colorama for Windows, each with its file hashes.
  • Widening requires-python to 3.11 forked numpy into 2.4.6 for 3.11 and 2.5.5 for later Pythons.
  • uv locks again only when pyproject.toml changes; --locked turns that into an error, the right setting for CI.
DEEP DIVE: what triggers a clean resolve, conflicting extras and groups, limiting platforms, pylock.toml and requirements files

What triggers a clean resolve

Most re-locks start from the old answer and keep each version that still fits. Some changes throw those preferences away and resolve from scratch: a new resolution mode, a new fork strategy, a change to environments or to requires-python. Others keep them: the pre-release mode, exclude-newer and --upgrade-package.

uv 0.13.10’s tests pin down the tightening case. With 2.0.0 locked, changing ok>=2,<3 to ok>=2,<2.5 fails --locked, because the lock records the ranges themselves. A rewrite that means the same set, such as >=1.0, >=2, <3, <4 for >=2.0.0,<3, passes. uv lock --check is the same test as --locked, --check-exists matches --frozen, and --dry-run prints the changes without writing them.

Conflicting extras and groups

Two extras or groups that can never be installed together, such as a CPU and a GPU build of one library, would make one resolution impossible. List them under tool.uv.conflicts and uv solves each side in its own fork. The lock holds both answers, and an install picks the one for the extra or group you asked for.

Limiting platforms

tool.uv.environments narrows the universal resolution, for example to Linux and macOS only, so a Windows-only conflict stops mattering. required-environments works the other way: locking fails unless every listed platform has a wheel. Either way, wheels that no supported platform or Python could install are pruned from the lock.

pylock.toml and requirements files

PEP 751, final since March 2025, defines pylock.toml: one standard lockfile with versions, sources and hashes that any installer can read. uv export --format pylock.toml writes one from uv.lock, and uv export --format requirements.txt writes the older pinned list with hashes. uv pip compile --generate-hashes does the same from a requirements file.

pip can read the standard file too, as experiments: pip lock writes one, and since pip 26.1 pip install -r pylock.toml installs from one. uv pip install -r pylock.toml works as well, with a preview warning.

ERRORS THIS CHAPTER EXPLAINS

The lockfile at `uv.lock` needs to be updated, but `--locked` was provided.
pyproject.toml changed after the last lock
run uv lock on your machine, review the diff and commit it
cause: Requirements for `…` changed from `…` to `…`
the line names exactly which range changed and how
check that the edit to that range was meant, then lock and commit

Putting it on disk: the installer and the cache

The lock says exactly what .venv should hold on this machine. Now uv has to put it there. It fetches each wheel, unpacks it and lays its files out where Python imports from. With pip, that whole job happens again in every environment, unzipping and copying every file each time. With uv, the slow part happens once per machine, and the result stays in a folder that every project shares. Why does installing with uv take a fraction of pip’s time?

STEP 01 / 05

THE MAP SO FAR

Fig 6.1Follow the accent path: index client to cache once, then cache through the installer into .venv for each project.

Two parts are new. The installer reads uv.lock and makes .venv hold exactly what it lists for this machine. The cache is one folder in your home directory, ~/.cache/uv, that keeps everything uv has downloaded, unpacked or built, for every project.

Files take one path. The index client downloads a wheel into the cache once. The installer then takes its files from the cache into the .venv of every project that locks that version, without fetching it again.

STEP 02 / 05

THE CACHE KEEPS WHEELS ALREADY UNZIPPED

Fig 6.2Each row is one bucket; the accent row holds the unzipped files every install is made from.

~/.cache/uv is the same path on macOS and Linux; Windows keeps it in %LOCALAPPDATA%\uv\cache. Inside are buckets, folders whose names end in a format number that changes when uv changes that bucket’s layout. simple-v28 keeps index pages, archive-v0 keeps every wheel already unzipped into a folder, and sdists-v11 keeps wheels uv built from source.

Several uv processes can use the cache at once, so two terminals can sync two projects together. uv cache prune removes unused entries, and uv cache clean removes everything, or one package with uv cache clean numpy.

STEP 03 / 05

INSTALLING IS LINKING, NOT COPYING

Fig 6.3Same package, two installers. The accent step is the only one uv repeats per .venv, and it copies no data.

To put numpy into .venv, uv clones each file from its folder in archive-v0. A clone is a new file that shares the original’s data on disk until one of them changes, so it takes almost no time or space. APFS on macOS supports clones, and so do some Linux filesystems. Clone is the default on macOS, and on Linux since uv 0.10.5.

Where cloning fails, uv makes a hard link, and where that fails too, it copies. Windows defaults to hard links. pip keeps no unzipped copy: for every environment it opens the wheel, writes every file out of it and compiles .pyc files. uv also runs 50 downloads at once and skips .pyc compilation by default.

uv’s README puts the result at “10-100x faster than pip”, measured installing Trio’s dependencies with a warm cache. The warm cache is the point: once a wheel sits in archive-v0, installing it into another project is mostly file-system bookkeeping.

STEP 04 / 05

SYNC MAKES .venv MATCH THE LOCK EXACTLY

Fig 6.4Read across each row; the accent row is the package uv sync removes because the lock doesn’t list it.

uv sync compares what .venv holds with what uv.lock lists for this platform. It installs what is missing, replaces versions that differ and removes anything the lock doesn’t list. Say a teammate’s .venv still has pandas 3.0.0 and six 1.17.0 from an old experiment (illustrative). Sync keeps requests and numpy, replaces pandas with 3.1.1 and removes six.

A package counts as installed when its version, platform tags and build settings match the lock; uv doesn’t re-hash its files. fx-report itself goes in as an editable install, so edits under src/ are live, and the dev group comes too unless you pass --no-dev.

In the output, a replaced version counts twice: Uninstalled 2 packages covers pandas 3.0.0 and six, and Installed 1 package is pandas 3.1.1. Prepared 1 package means one wheel was fetched into the cache first.

UV SYNC ON THE TEAMMATE’S MAC (TIMINGS ILLUSTRATIVE)
$ uv sync
Resolved 17 packages in 3ms
Prepared 1 package in 410ms
Uninstalled 2 packages in 38ms
Installed 1 package in 61ms
 - pandas==3.0.0
 + pandas==3.1.1
 - six==1.17.0
STEP 05 / 05

uv run CHECKS, SYNCS, THEN RUNS

Fig 6.5Follow 1 to 4; your code starts only at the accent step, after the lock and .venv are checked.

uv run fx-report checks that uv.lock still matches pyproject.toml (chapter 05), locks again if it doesn’t, installs what .venv is missing, then runs the command with .venv/bin first on PATH. You never activate anything. Unlike uv sync, uv run removes nothing: a package you added by hand stays until the next sync.

--locked fails on a stale lock instead of rewriting it, which is what CI wants. --frozen skips the check and uses uv.lock as it is. --with rich adds a package for one run, in a throwaway layer over .venv that the project never sees.

THREE WAYS TO RUN
$ uv run fx-report           # check the lock, install what is missing, run
$ uv run --locked pytest       # in CI: fail if uv.lock is stale
$ uv run --with rich python -c "import rich; rich.print('[b]ok[/b]')"

COMMON QUESTIONS

Is it safe to delete ~/.cache/uv?
Yes. It is only a copy: uv downloads and rebuilds what it needs, slower the first time. Environments made with clones or hard links keep their files.
Why does my first import pandas feel slower than with pip?
pip compiled .pyc files at install time; uv leaves that to Python’s first import. Pass --compile-bytecode where startup time matters.
What does uv pip install do differently from uv sync?
It adds what you name and removes nothing, like pip. uv pip sync requirements.txt is the exact version.

WHAT YOU NOW KNOW

  • The cache keeps each wheel unzipped once in archive-v0, shared by every project on the machine.
  • Installing clones files from the cache on macOS and Linux and hard-links them on Windows; pip copies every file and compiles .pyc.
  • uv sync removes what the lock doesn’t list; uv run checks the lock and installs only what is missing.
DEEP DIVE: what uv writes into site-packages, concurrency and CI caches, Docker images, the uv pip interface

What uv writes into site-packages

For each package, uv links the files from the cache, writes its entry-point scripts into .venv/bin, moves anything under the wheel’s .data/ folder to where it belongs, and then writes the .dist-info records: INSTALLER containing uv, REQUESTED, direct_url.json, uv_cache.json and RECORD.

fx-report is installed editable. Its [project.scripts] line becomes .venv/bin/fx-report, and a .pth file in site-packages adds src/ to Python’s import path, so an edit under src/fx_report/ is live without reinstalling.

Concurrency and CI caches

uv runs 50 downloads at once, and as many builds and installs as the machine has CPU cores. UV_CONCURRENT_DOWNLOADS, UV_CONCURRENT_BUILDS and UV_CONCURRENT_INSTALLS change those limits, for a slow proxy or a small CI runner.

Before saving ~/.cache/uv as a CI cache, run uv cache prune --ci. It keeps the wheels uv built from source, which are slow to make again, and drops downloaded wheels and unzipped archives, which are often as quick to download as to restore.

Docker images

A Docker build that mounts the cache with RUN --mount=type=cache puts it on a different filesystem from .venv, so links fail. Set UV_LINK_MODE=copy to copy on purpose, without the warning, and UV_COMPILE_BYTECODE=1 so the image ships its .pyc files.

Install in two layers. Copy only pyproject.toml and uv.lock, then run uv sync --locked --no-dev --no-install-project: Docker reuses that dependency layer until the lock changes. Then copy the source and run uv sync --locked --no-dev to add the project itself.

The uv pip interface

uv pip install follows pip’s commands but not all of its habits. It reads no pip.conf and no PIP_INDEX_URL, takes a package from the first index that has it, installs only into a virtual environment unless you pass --system, and has no --user. It compiles no bytecode, and it builds sdists in isolation by default.

uv pip compile prints the pinned list to the terminal; pass -o requirements.txt to write the file.

ERRORS THIS CHAPTER EXPLAINS

Failed to hardlink files; falling back to full copy. This may lead to degraded performance.
the cache and .venv are on different filesystems, such as a Docker cache mount
move the cache with UV_CACHE_DIR, or set UV_LINK_MODE=copy to copy on purpose without the warning

Packages with no wheel: builds from source

Everything so far assumed a wheel exists. The team’s rates-client is published on the fxco index only as an sdist, a source archive (illustrative), and fx-report itself is source in a folder. Before uv can install either, something has to turn source into a wheel, and that means running the package’s own build code on your machine. What happens when the only file for a package is source code?

STEP 01 / 04

THE MAP SO FAR

Fig 7.1The accent box turns source into a wheel and stores it in the cache, beside the downloaded ones.

The build frontend is the part of uv that drives a package’s own build tool. It takes an sdist from the index client, a git checkout or a project folder, and asks that package’s build tool to make a wheel.

The wheel goes into the cache’s sdists-v11 bucket, and from there into .venv exactly like a downloaded one. This chapter adds the build frontend and its two arrows: source in, built wheel out.

STEP 02 / 04

AN SDIST CARRIES ITS OWN BUILD RECIPE

Fig 7.2Follow 1 to 5; the accent environment exists only for this build and holds only the backend.

Every sdist carries a pyproject.toml, and its [build-system] table names a build backend and the packages that backend needs. rates-client’s says uv_build. uv unpacks the sdist, resolves those build requirements on their own, apart from fx-report’s versions, and installs them into a temporary environment under builds-v0.

That is build isolation: the backend sees only its own requirements, never fx-report’s .venv. uv then calls the backend’s PEP 517 hooks, standard functions every backend provides: one for the metadata, then build_wheel() for the wheel. A project with no [build-system] table gets setuptools’ legacy backend, setuptools.build_meta:__legacy__.

RATES-CLIENT’S OWN PYPROJECT.TOML (TRIMMED)
# rates-client/pyproject.toml (trimmed)
[project]
name = "rates-client"
version = "2.0.0"
requires-python = ">=3.11"
dependencies = ["requests>=2.32", "pandas>=2.2"]

[build-system]
requires = ["uv_build>=0.13.10,<0.14"]
build-backend = "uv_build"
STEP 03 / 04

METADATA WITHOUT A BUILD, WHEN THE SOURCE ALLOWS IT

Fig 7.3Rows run in uv’s order; the accent row answers without running any of the package’s code.

The resolver needs only an sdist’s dependencies, and a full build is slow and runs the package’s code. So uv tries cheaper sources first. Dependencies written out in [project] and not listed under dynamic are static metadata: uv reads them straight from pyproject.toml.

Next comes PKG-INFO, the metadata file inside every sdist, when its Metadata-Version is 2.2 or later and it doesn’t mark the dependencies as Dynamic. Then the backend’s prepare_metadata_for_build_wheel hook, and only then a full build. rates-client’s dependencies are static, so resolving it builds nothing.

STEP 04 / 04

A BUILT WHEEL IS KEPT BY ITS SOURCE

Fig 7.4Each row is a kind of source; the accent row shows a git dependency rebuilds only when its commit changes.

uv files each built wheel in sdists-v11 under a key: for an sdist on an index, the sdist’s revision and the build settings. A git dependency, a package taken straight from a git repository, is keyed by its commit. The next uv sync, in this project or any other, finds the wheel there and builds nothing.

uv build makes fx-report’s own release files: first the sdist in dist/, then the wheel built from that sdist, which proves the sdist is complete. uv_build handles pure Python only; a package with compiled code needs another backend, such as maturin or scikit-build-core.

COMMON QUESTIONS

Why did uv lock run a compiler?
A package in the tree had only an sdist with dynamic metadata, so uv built it to learn its dependencies. A published wheel or static metadata in that package avoids the build.
What if a build needs a package already in my environment, such as torch?
Turn isolation off for that package with no-build-isolation-package, so its build sees .venv, or add the package to its build environment with extra-build-dependencies.
Can I keep using setuptools or hatchling?
Yes. uv drives any PEP 517 backend, so existing projects build unchanged. uv init --build-backend hatchling starts a new project with one.

WHAT YOU NOW KNOW

  • An sdist names its own build backend, which uv runs in a throwaway environment with its own separate resolve.
  • uv reads static metadata first, so rates-client resolves without a build.
  • Built wheels are cached by source revision and settings, git ones by commit; --no-build refuses sdists entirely.
DEEP DIVE: the PEP 517 hooks, when isolation gets in the way, build constraints, editable installs, resolving can run code

The PEP 517 hooks

A backend is a Python module with standard functions. get_requires_for_build_wheel returns extra packages the build needs. prepare_metadata_for_build_wheel writes only the .dist-info folder. build_wheel and build_sdist write a file into the folder they are given and return its name. build_editable, from PEP 660, makes the wheel behind an editable install.

When isolation gets in the way

Some packages import a heavy dependency, such as torch, inside their build. --no-build-isolation builds every package against .venv instead, no-build-isolation-package does it for named packages only, and extra-build-dependencies adds packages to one package’s isolated build environment. Build requirements always resolve to their highest allowed versions, because nothing locks them.

Build constraints

A build backend’s version isn’t in uv.lock, so a new backend release can change tomorrow’s build. Bound it in [build-system] requires, as uv init does with uv_build>=0.13.10,<0.14, and use build-constraint-dependencies to cap a backend that a dependency’s sdist asks for.

Editable installs

uv sync installs fx-report through uv_build’s build_editable hook. The result is a tiny wheel holding a .pth file that puts src/ on Python’s import path, so edits are live without reinstalling. In a Docker image, use uv sync --no-editable: the image then holds a real copy of the package and needs no source folder beside it.

Resolving can run code

An sdist without static metadata runs its build backend while uv resolves, before you have run anything yourself, so a malicious sdist can act during uv lock. The resolver chapter of the supply chain attacks tutorial shows how a poisoned release reaches a machine through that step.

Python itself: finding and installing interpreters

Every chapter so far assumed the laptop already had Python 3.14. That isn’t always true: the Windows laptop has 3.12 from the Microsoft Store, the old reporting server has 3.11, and a fresh CI runner may have no Python at all. Before uv can make .venv, it has to pick one interpreter, and download one when nothing on the machine fits. Which Python does a project get, and where does it come from?

STEP 01 / 04

THE MAP SO FAR

Fig 8.1The accent finder reads the pin and picks an interpreter, downloading one only when none fits.

The Python finder chooses the interpreter .venv is made from. It reads .python-version in the project and looks through the interpreters already on the machine. When none fits, it downloads a prebuilt one into uv’s own folder. Interpreters uv downloaded this way are managed Pythons.

This chapter adds four parts: the finder, the pin file, the managed Pythons in ~/.local/share/uv/python, and releases.astral.sh, the server they are downloaded from.

STEP 02 / 04

uv LOOKS IN A FIXED ORDER

Fig 8.2Rows run in search order; the accent row is where uv stops on the Mac.

uv looks for an interpreter in a fixed order and stops at the first one that fits. First comes a virtual environment, the active one or the project’s .venv. Next come the Pythons uv installed itself, newest first. Then python, python3 and python3.x on PATH, where uv takes the first that fits, not the newest. On Windows, the registry and Microsoft Store Pythons come next. Last, uv downloads one.

The default, python-preference = "managed", puts uv’s own Pythons ahead of the system’s, but an installed system Python still beats a download. On the Mac laptop (illustrative) there is no .venv yet, and the managed 3.14.10 matches the 3.14 pin, so the search stops at row 2. On the Windows laptop, the Store’s Python 3.12 doesn’t match the pin, so uv downloaded 3.14 there once.

STEP 03 / 04

.python-version AND requires-python ANSWER DIFFERENT QUESTIONS

Fig 8.3The bracket is what the lock covers; the accent slot is the one Python this checkout uses.

requires-python = ">=3.12" in pyproject.toml says which Pythons the project supports, and the lockfile covers all of them. .python-version says which one this checkout uses for .venv. uv init writes it with the major and minor version of the first interpreter discovery finds, and uv python pin changes it. fx-report pins 3.14.

With no pin, uv takes the first interpreter that satisfies requires-python. With nothing suitable installed, it downloads 3.15, uv’s default since 0.13.0. The old server’s 3.11 is outside fx-report’s range, so uv never makes fx-report’s .venv from it.

PIN THE VERSION, THEN INSTALL IT (TIMING ILLUSTRATIVE)
$ uv python pin 3.14
Pinned `.python-version` to `3.14`
$ uv python install 3.14
Installed Python 3.14.10 in 1.92s
 + cpython-3.14.10-macos-aarch64-none (python3.14)
STEP 04 / 04

A DOWNLOADED PYTHON IS A PREBUILT ARCHIVE

Fig 8.4Two ways to get Python 3.14; the accent column needs no compiler.

uv’s Pythons come from python-build-standalone, a project Astral has run since 17 December 2024. Since uv 0.10.9 they are downloaded from releases.astral.sh, Astral’s mirror of the project’s GitHub releases. uv unpacks the archive into ~/.local/share/uv/python and links python3.14 into ~/.local/bin. Each .venv’s bin/python links to one of these folders.

pyenv compiles CPython from source on your machine. That needs a C compiler and the system’s libraries, and it takes minutes. uv’s install is a download and an unpack, so it needs neither.

COMMON QUESTIONS

Does uv replace the system Python?
No. It installs its own Pythons beside the system’s, under ~/.local/share/uv/python, and leaves the operating system’s copy alone.
Can I forbid downloads?
Yes. Set python-downloads = "never", or python-preference = "only-system" to use only Pythons already installed.
Does uv support free-threaded Python?
Yes: request 3.14t. Since uv 0.9, free-threaded builds can be chosen without opting in, though the standard build is preferred.

WHAT YOU NOW KNOW

  • uv searches a .venv, its own Pythons, then PATH (first match, not newest), then downloads one.
  • requires-python sets the range the lock covers; .python-version picks 3.14 for this checkout.
  • Managed Pythons are prebuilt archives from releases.astral.sh, unpacked without compiling; pyenv compiles from source.
DEEP DIVE: preference and download settings, python on PATH, standalone builds, other implementations

Preference and download settings

python-preference takes four values. managed, the default, prefers uv’s Pythons but uses a system one before downloading. only-managed ignores system Pythons, system prefers them, and only-system never uses uv’s own. python-downloads is automatic (the default), manual (only uv python install downloads) or never. UV_PYTHON_INSTALL_DIR moves the folder.

A .venv’s pyvenv.cfg names the minor-version folder, cpython-3.14-macos-aarch64-none, not the patch folder cpython-3.14.10-macos-aarch64-none. That name links to the newest installed patch, so uv python upgrade 3.14 can move it to a newer 3.14 release and every .venv keeps working.

python on PATH

uv python install 3.14 puts python3.14 in ~/.local/bin, and that has been stable since uv 0.8. --default also installs python and python3 there, and it is still a preview feature. If ~/.local/bin isn’t on PATH, uv python update-shell adds it to your shell’s startup file.

What is different about standalone builds

python-build-standalone builds are made to be unpacked into any folder, so they differ from a Linux distribution’s Python in small ways. On Linux the interactive prompt edits lines with libedit, not readline. Paths recorded at build time point at the build machine, and uv fixes them up when it unpacks the archive. The project lists these differences on its quirks page.

Other implementations

uv also installs PyPy (up to Python 3.12), GraalPy and Pyodide: uv python install pypy@3.12, for example. A CPython debug build has a d suffix, such as 3.13d, and a free-threaded build a t, such as 3.14t.

Outside a project: tools and scripts

Not everything Python is a project. The team lints with ruff, a command-line tool that shouldn’t live in fx-report’s .venv, and keeps scripts/backfill.py, a one-file script that needs requests and nothing else. With pip, each meant a hand-made virtual environment or a package installed into the wrong Python. How do you run a tool or a one-file script without a project?

STEP 01 / 04

THE MAP SO FAR

Fig 9.1The accent parts are environments uv makes for you: installed tools, and the cache’s environments bucket.

Some environments you never create by hand. Each tool you install gets a tool environment, a virtual environment that holds one command-line tool and what it needs, in ~/.local/share/uv/tools.

One-off tool runs and scripts get cached environments in the cache’s environments-v2 bucket. This chapter adds both.

STEP 02 / 04

uvx RUNS A TOOL IN A THROWAWAY ENVIRONMENT

Fig 9.2Follow 1 to 3; the accent environment is reused on the next run until you ask for a newer ruff.

uvx is short for uv tool run. uvx ruff check resolves ruff, builds an environment for it in the cache and runs ruff check from there. The next uvx ruff reuses that environment until you ask for ruff@latest or clear the cache with uv cache clean.

A tool’s environment ignores the project’s .python-version and its dependencies. --from names the package when its command has a different name, and --with adds a plugin to the same environment.

STEP 03 / 04

uv tool install KEEPS ONE ENVIRONMENT PER TOOL

Fig 9.3Three kinds of environment side by side; the accent column is the one that stays until you uninstall.

uv tool install ruff makes an environment in ~/.local/share/uv/tools/ruff and links the ruff command into ~/.local/bin. Each tool has its own environment, so two tools can need clashing versions of the same library. uv tool upgrade ruff upgrades it within the requirement you installed it with.

This is the job pipx did, the older tool that put each command-line app into its own virtual environment. uv tool install replaces pipx install, and uvx replaces pipx run.

RUN RUFF ONCE, THEN INSTALL IT (TIMINGS ILLUSTRATIVE)
$ uvx ruff check               # first run: builds a cached environment
Installed 1 package in 6ms
All checks passed!
$ uvx ruff check               # later runs reuse it and print nothing extra
All checks passed!
$ uv tool install ruff
Resolved 1 package in 180ms
Prepared 1 package in 1.10s
Installed 1 package in 5ms
 + ruff==0.17.6
Installed 1 executable: ruff
STEP 04 / 04

A SCRIPT CAN CARRY ITS OWN DEPENDENCIES

Fig 9.4One row per line of the block; the accent row is all the script needs to run anywhere uv is installed.

Inline script metadata (PEP 723) lets one file declare its Python range and dependencies in a comment block between # /// script and # ///. uv run scripts/backfill.py reads the block, ignores the project’s dependencies and runs the script in a cached environment that holds requests and what requests needs.

uv add --script scripts/backfill.py requests edits the block for you, and uv lock --script writes backfill.py.lock beside it. The exclude-newer line makes uv ignore releases uploaded after that time, so the script resolves the same versions next month.

SCRIPTS/BACKFILL.PY: THE BLOCK AND THE CODE
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.12"
# dependencies = ["requests>=2.34"]
#
# [tool.uv]
# exclude-newer = "2026-11-30T00:00:00Z"
# ///
"""Refetch one missed day of exchange rates."""
import sys

import requests

day = sys.argv[1]  # for example 2026-11-27
reply = requests.get(f"https://rates.partner.example/v1/{day}", timeout=10)
reply.raise_for_status()
print(len(reply.json()["rates"]), "rates for", day)

COMMON QUESTIONS

When do I use uvx, and when uv tool install?
uvx for something you run now and then; uv tool install for a command you type daily and want on PATH.
Can a script use my project’s packages?
Not while it has a # /// script block: the block replaces the project. Without one, uv run script.py inside the project uses .venv.
Does uv have a formatter and a type checker built in?
uv format (ruff) and uv check (ty) exist as preview commands in uv 0.13.10. They aren’t stable yet.

WHAT YOU NOW KNOW

  • uvx ruff builds a cached environment once and reuses it until you ask for a newer ruff.
  • uv tool install ruff keeps one environment per tool and puts the command in ~/.local/bin.
  • A # /// script block lets backfill.py run with only requests, in its own cached environment.
DEEP DIVE: tool versions and upgrades, scripts with locks and dates, where tool environments live

Tool versions and upgrades

uvx ruff@0.17.6 runs that exact version, and uvx ruff@latest asks the index for a newer one. Plain uvx ruff takes the version already cached. uv tool install records the requirement you gave it, so uv tool upgrade ruff stays inside it, and uv tool upgrade --all upgrades every tool. --with-executables-from also links the commands of another package installed in the same environment.

Scripts with locks and dates

uv lock --script scripts/backfill.py writes scripts/backfill.py.lock, a lockfile for the one script, and later runs install from it. exclude-newer in the block’s [tool.uv] table takes a timestamp or, since uv 0.9.17, a duration such as "7 days" or P7D, which ignores anything uploaded in the last week.

The first line, #!/usr/bin/env -S uv run --script, lets you run ./backfill.py directly once the file is executable: the shell hands it to uv, which reads the block.

Where tool environments live

UV_TOOL_DIR moves the tool environments, and UV_TOOL_BIN_DIR moves the folder their commands are linked into. On macOS and Linux the commands are symlinks; on Windows they are copies. uvx environments live in the cache, so uv cache clean deletes them and the next uvx builds them again. Installed tools sit outside the cache and survive it.

Many packages, one lock: workspaces and sources

The team now edits rates-client as often as fx-report, and publishing a new sdist to fxco for every change is slow. So they move it into fx-report’s repository, as packages/rates-client. Two packages in one repository could have two lockfiles and two environments that drift apart, and fx-report should use the copy next to it, not the one on the index. How do two packages in one repository share one lock and one environment?

STEP 01 / 04

THE MAP SO FAR

Fig 10.1The accent package now shares the root’s lockfile and environment.

A workspace is a repository whose root pyproject.toml lists other packages as members. All of them share one uv.lock and one .venv at the root.

This chapter adds packages/rates-client/ as a member of fx-report’s workspace, linked to the root pyproject.toml that lists it.

STEP 02 / 04

ONE REPOSITORY, TWO PACKAGES, ONE LOCK

Fig 10.2Two packages feed the accent lockfile; there is still one .venv.

The root pyproject.toml gains [tool.uv.workspace] with members = ["packages/*"], and rates-client = { workspace = true } replaces the fxco index pin. uv lock now resolves both packages together into one lock, so they can’t disagree on pandas. The workspace’s requires-python is the intersection of the members’: rates-client’s >=3.11 and fx-report’s >=3.12 give >=3.12.

Members are always installed editable, so a change in packages/rates-client/src is live in .venv at once. uv run --package rates-client pytest runs one member’s tests.

THE ROOT PYPROJECT.TOML (TRIMMED)
# fx-report/pyproject.toml, the workspace root (trimmed)
[project]
name = "fx-report"
dependencies = ["requests>=2.34.2", "pandas>=3.1.1", "rates-client>=2.0"]

[tool.uv.workspace]
members = ["packages/*"]

[tool.uv.sources]
rates-client = { workspace = true }
STEP 03 / 04

SOURCES SAY WHERE A PACKAGE COMES FROM

Fig 10.3One row per kind of source; the accent row is the one this chapter switched to.

A source in [tool.uv.sources] overrides where uv fetches one package. There are five kinds: index (a named index, as in chapter 02), git with a tag, branch or rev, path (installed editable only with editable = true), url for an archive, and workspace.

Only uv reads sources. A published fx-report carries only rates-client>=2.0 in its metadata, so anyone who installs it with pip gets rates-client from an index.

STEP 04 / 04

WHEN A WORKSPACE IS THE WRONG TOOL

Fig 10.4Two ways to keep packages side by side; the accent row is the rule that decides between them.

One lock means every member must accept the same versions and the same Python range. If a second job needs pandas 2 while fx-report needs pandas 3, a workspace can’t hold both: uv lock fails for every member.

Keep them as separate projects instead, each with its own lock and .venv, and point one at the other with a path dependency, a requirement uv takes from a folder on disk: rates-client = { path = "../rates-client", editable = true }.

COMMON QUESTIONS

Is a workspace the same as a monorepo?
A workspace is one way to run part of a monorepo: the packages that should share versions. A monorepo can hold several workspaces.
Can members have different dependencies?
Yes. Each lists its own, and they share one resolution, so a package both need gets one version.
How does uv sync treat members?
It installs the root and every member editable. --package limits a sync or a run to one member.

WHAT YOU NOW KNOW

  • members = ["packages/*"] puts rates-client into fx-report’s one uv.lock and one .venv.
  • { workspace = true } replaced the fxco index pin; sources are read only by uv.
  • When two packages need clashing versions, use path dependencies with separate locks.
DEEP DIVE: workspace layouts, sources by platform, conflicts between members, publishing from a workspace

Workspace layouts

The root needn’t be a package. A root pyproject.toml with [tool.uv.workspace] and no [project] table is a virtual root: it only groups its members. exclude = ["packages/legacy"] leaves a folder out of a glob. Running uv init inside a workspace adds the new project as a member, and sources in the root’s [tool.uv.sources] apply to every member.

Sources by platform

A source can carry a marker, as in { index = "fxco", marker = "sys_platform == 'darwin'" }, so it applies only where the marker holds. A list of sources split by markers sends one package to different places on different platforms, for example one index of CPU builds and another of GPU builds.

Conflicts between members

When two members truly need clashing versions, tool.uv.conflicts can declare them, with entries such as { package = "fx-report" } and { package = "batch-job" }. uv then resolves each side separately inside the one lock, and the two can’t be installed into the same .venv together. It is a last resort: two separate projects are usually simpler.

Publishing from a workspace

uv build --package rates-client builds one member’s sdist and, from it, its wheel into dist/. uv version --bump minor, run in the member’s folder, raises the version in its pyproject.toml. uv publish uploads the files. To PyPI from a CI job it can use Trusted Publishing, which trades the job’s own identity token for short-lived upload rights, so no stored token is needed.

The whole picture

Here is every part from the ten chapters on one map, numbered to match the table below.

Find a number on the map, then its row below: what the part does, where it lives and what it checks.

ONE SYNC, END TO END

Take uv sync on the Windows laptop. The Python finder (11) reads .python-version (12) and picks the managed Python 3.14 (13). uv checks that uv.lock (7) still matches pyproject.toml (5), so the resolver (6) has nothing to do. The index client (2) downloads colorama 0.4.6 from PyPI (3), and the build frontend (10) turns rates-client’s source from fxco (4) into a wheel. Both land in the cache (9), and the installer (8) links all 16 packages into .venv (1).

  1. 1virtual environment (.venv)

    holds a link to one Python and the packages one project uses

    attached to
    the project folder
    checks
    nothing; Python reads its config file at startup
    when wrong
    an import error from a Python outside .venv
  2. 2index client

    fetches index pages, metadata and files, and picks the wheel that fits

    attached to
    the uv process
    checks
    each download’s hash against the index or the lockfile
    when wrong
    a refused download whose hash doesn’t match
  3. 3PyPI

    lists every file of every public release

    attached to
    the internet, pypi.org/simple
    checks
    nothing about your project; it serves what maintainers uploaded
    when wrong
    no wheel for your platform, so uv builds from source
  4. 4company index (fxco)

    serves the company’s own packages

    attached to
    the company network
    checks
    nothing uv relies on; uv asks it only for names pinned to it
    when wrong
    rates-client taken from the wrong index: its source pin is missing
  5. 5pyproject.toml

    lists what the project needs, as version ranges

    attached to
    the project root
    checks
    nothing; uv only reads the ranges in it
    when wrong
    ranges so narrow that no set of versions fits them all
  6. 6resolver

    picks one version of every package that fits every range

    attached to
    the uv process, between pyproject.toml and the lockfile
    checks
    every range, platform condition and Python requirement in the tree
    when wrong
    “No solution found”, with the clashing ranges spelled out
  7. 7uv.lock

    records exact versions and file hashes for every supported platform

    attached to
    the project root, committed to git
    checks
    that the ranges it was made from still match pyproject.toml
    when wrong
    CI stopping because the lockfile “needs to be updated”
  8. 8installer

    makes .venv hold exactly what the lockfile lists

    attached to
    the project’s .venv
    checks
    each package’s version, platform and build settings
    when wrong
    a package you installed by hand, gone after uv sync
  9. 9cache

    keeps index pages, unzipped wheels and built wheels for every project

    attached to
    your home directory, ~/.cache/uv
    checks
    whether a saved index page is still fresh
    when wrong
    slow full copies and a warning when it sits on another disk
  10. 10build frontend

    turns source code into a wheel in a throwaway environment

    attached to
    the uv process, for source archives and git
    checks
    that the build backend’s own requirements resolve
    when wrong
    a compiler or build error in the middle of uv lock or uv sync
  11. 11Python finder

    chooses the interpreter a project’s environment is made from

    attached to
    the uv process, before .venv exists
    checks
    the version against .python-version and requires-python
    when wrong
    a different Python than you expected, taken from PATH or downloaded
  12. 12.python-version

    names the Python version this checkout uses

    attached to
    the project root
    checks
    nothing; the Python finder reads it
    when wrong
    every command failing when the pin is outside requires-python
  13. 13managed Pythons

    prebuilt interpreters uv downloaded and unpacked

    attached to
    ~/.local/share/uv/python
    checks
    nothing; they are finished builds
    when wrong
    broken environments after uninstalling the Python they link to
  14. 14tools

    keep one environment per command-line tool

    attached to
    ~/.local/share/uv/tools, with commands in ~/.local/bin
    checks
    nothing; each tool resolves on its own
    when wrong
    “command not found” when ~/.local/bin isn’t on PATH
  15. 15workspace member (rates-client)

    a second package sharing the root’s lockfile and environment

    attached to
    the repository, listed in the root pyproject.toml
    checks
    that all members accept one set of versions and one Python range
    when wrong
    one failed lock for every member when two need clashing versions
  16. ·sources ([tool.uv.sources])

    say where uv fetches one package: an index, git, a path or the workspace

    attached to
    pyproject.toml
    checks
    nothing outside uv; other tools ignore them
    when wrong
    users of the published package getting a different version from an index
  17. ·dependency groups

    list packages for development only, such as pytest

    attached to
    pyproject.toml
    checks
    nothing; groups are never published
    when wrong
    test tools inside a production image, because the sync kept the dev group

WHAT UV REPLACES

These are the tools uv’s README says it replaces, each beside the uv command that does its job.

Each row is one older tool; the last column names the chapter that teaches its uv command.

THREE THINGS TO KEEP

  • uv reads what your project asks for, picks one version of every package, and writes that answer into a lockfile.
  • Every machine installs from that same lockfile, so a laptop, a teammate’s computer and a server get identical packages.
  • Commit the lockfile and make your build refuse a stale one, or it can install versions nobody reviewed.
Read next. Python supply chain attacks: how a poisoned release reaches you for what a lockfile, a cooldown and one index per name protect you from, and Testing in Python: how pytest, fixtures and mocks work for the tests fx-report’s dev group exists to run.
$ uv sync --locked
Lock once, sync everywhere.