Sub topic 17
The uv pip interface for existing workflows
This chapter assumes you know what pip and virtual environments do, you can use a terminal, and you have read the chapters on project environments and uv.lock. You will learn when to use uv pip instead of the project commands, and how its commands map to pip.
Two ways to use uv
uv offers two interfaces. The project interface (uv add, uv sync, uv run) edits pyproject.toml and keeps uv.lock current. The uv pip interface works like pip. It installs into an environment you choose and does not touch pyproject.toml or uv.lock.
Use uv pip when a project already has scripts, Dockerfiles, or CI jobs built around pip install and requirements.txt. It gives you uv's speed without a change in workflow.
Command mapping
| pip or related tool | uv equivalent |
|---|---|
| `python -m venv .venv` | `uv venv` |
| `pip install requests` | `uv pip install requests` |
| `pip install -r requirements.txt` | `uv pip install -r requirements.txt` |
| `pip install -e .` | `uv pip install -e .` |
| `pip uninstall requests` | `uv pip uninstall requests` |
| `pip freeze` | `uv pip freeze` |
| `pip list` | `uv pip list` |
| `pip-compile requirements.in` | `uv pip compile requirements.in -o requirements.txt` |
| `pip-sync requirements.txt` | `uv pip sync requirements.txt` |
A worked example
This session creates an environment, installs packages, and records exact versions.
uv venv
source .venv/bin/activate
uv pip install httpx typer
uv pip freeze > requirements.txtuv venv creates .venv in the current directory. On Windows, activate it with .venv\Scripts\activate. If you skip activation, uv pip still finds a .venv in the current or a parent directory. It does not do this when another environment is active through VIRTUAL_ENV.
Compile and sync
uv pip compile takes loose requirements and resolves them to pinned versions, as pip-compile does. Put your direct dependencies in requirements.in:
httpx>=0.27
typer>=0.12Then compile and sync:
uv pip compile requirements.in -o requirements.txt
uv pip sync requirements.txtuv pip sync makes the environment match the file exactly. It installs missing packages and removes extras. uv pip install -r only adds packages, so stray packages remain.
Common errors
- No virtual environment found.
uv pip installrefuses to change the system Python. Runuv venvfirst, or pass--systemif you really mean to install globally, such as in a container. - Mixing interfaces. Packages installed with
uv pip installare not recorded inpyproject.toml. A lateruv syncremoves packages it does not know about, and your manual installs disappear. - Assuming pip's behavior everywhere. uv resolves differently in some cases. For example, with
--index-urland--extra-index-urlit searches all indexes and picks the first one that has the package by default, rather than the highest version across them. Use--index-strategyto change this.
Exercise
Your team has a requirements.in file and a compiled requirements.txt. A teammate ran uv pip install somepackage by hand in the shared environment. Which command makes the environment match requirements.txt again, and why does uv pip install -r requirements.txt not do the same?
Show answer
Run uv pip sync requirements.txt. It installs what is missing and uninstalls packages not listed in the file, including somepackage. uv pip install -r only adds or updates the listed packages and leaves extras in place.