uv pip sync: Make an Env Match a Requirements File
uv pip sync makes the environment exactly match a requirements file, installing what is missing and uninstalling what is not listed.
uv pip sync is the pip-tools pip-sync equivalent. Unlike pip install it removes packages not in the file, giving a deterministic environment for tests.
What it does
uv pip sync reads one or more requirements files and brings the active environment into exact agreement: missing packages are installed, extra packages are uninstalled, and versions are pinned to what the file specifies. It does not resolve, it installs verbatim.
Common usage
uv pip sync requirements.txt
uv pip sync requirements.txt dev-requirements.txt
uv pip sync --require-hashes requirements.txt
uv export --frozen -o requirements.txt && uv pip sync requirements.txtOptions
| Flag | What it does |
|---|---|
| <file> [<file> ...] | One or more requirements files to sync from |
| --require-hashes | Fail unless every requirement has a hash |
| --python <path> | Target a specific interpreter or venv |
| --no-deps | Install listed packages without their dependencies |
| --index-url <url> | Use a specific package index |
In CI
Pair uv export --frozen with uv pip sync to install the locked set into a plain venv, getting exact reproducibility without the full project workflow. Use --require-hashes for supply-chain safety. Cache $UV_CACHE_DIR so the wheels are reused across runs.
Common errors in CI
"error: In --require-hashes mode, all requirements must have a hash" means an unhashed line; regenerate with hashes via uv export. "No solution found" should not appear (sync does not resolve), but "Distribution not found" means a pinned version is missing from the index. A wrong --python path yields "Failed to locate a virtualenv".