How to Install the Exact Locked Versions with uv sync --locked
A project's uv.lock file records the exact version of every package it uses. uv sync --locked installs exactly those versions, and refuses to run if the lock file no longer matches pyproject.toml. That's how a second computer, or a build server, gets the same environment you have. This guide shows both with uv 0.13.10 on Python 3.15.2.
Syntax
uv sync --locked
| Part | What it means |
|---|---|
uv sync | Makes the project's .venv match the lock file, creating it if needed |
--locked | Uses uv.lock as it is, and stops with an error if it's out of date with pyproject.toml |
uv's locking and syncing guide says: "If the lockfile is not up-to-date, uv will raise an error instead of updating the lockfile."
The Example
A small project called price-tags prints a price with thousands separators, using one package, humanize. Its uv.lock pins humanize 4.17.0. The guide rebuilds its environment from the lock file, then changes pyproject.toml by hand to see what --locked does.
Prerequisites
- uv, with a project that has a
uv.lockfile. This guide uses uv 0.13.10 with Python 3.15.2.
Step 1: See the Project Run
The project was made with uv init --python 3.15 price-tags and uv add humanize, and its command prints a price:
uv run price-tags
Price: 1,234,567

Step 2: Rebuild the Environment from the Lock File
Delete the environment, as if you had just cloned the project onto another computer:
- macOS / Linux
- Windows (PowerShell)
rm -rf .venv
Remove-Item -Recurse -Force .venv
Then rebuild it from uv.lock:
uv sync --locked
Using CPython 3.15.2 interpreter at: /Library/Frameworks/Python.framework/Versions/3.15/bin/python3.15
Creating virtual environment at: .venv
Resolved 2 packages in 4ms
Installed 2 packages in 7ms
+ humanize==4.17.0
+ price-tags==0.1.0 (from file:///Users/you/source/price-tags)

uv created a new .venv and installed exactly the versions in the lock file: humanize==4.17.0, even if a newer humanize has come out since. The command works unchanged in PowerShell.
Step 3: See --locked Refuse a Lock File That's Out of Date
Add a second package to pyproject.toml by hand, without running uv add, so the lock file no longer matches:
dependencies = [
"humanize>=4.17.0",
"tabulate>=0.9",
]

Sync again:
uv sync --locked
Resolved 3 packages in 362ms
error: The lockfile at `uv.lock` needs to be updated, but `--locked` was provided.
cause: Requirements for `price-tags==0.1.0` differ; added: tabulate>=0.9
hint: To update the lockfile, run `uv lock`.

uv noticed the difference, named it in the cause line, and stopped without installing anything. Without --locked, uv sync would have updated the lock file and carried on. uv's guide says "Locking and syncing are automatic in uv", and --locked is how you turn the automatic locking off.
Step 4: Update the Lock File
uv lock
Resolved 3 packages in 5ms
Added tabulate v0.10.0
uv lock resolved the new requirement and pinned tabulate 0.10.0. Now uv sync --locked succeeds:
Resolved 3 packages in 4ms
Prepared 1 package in 262ms
Installed 1 package in 2ms
+ tabulate==0.10.0

Commit uv.lock with pyproject.toml: uv's project layout guide says it "should be checked into version control, allowing for consistent and reproducible installations".
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Editing pyproject.toml by hand and forgetting the lock | uv sync --locked stops: The lockfile at uv.lock needs to be updated | Run uv lock, or use uv add, which updates both files |
Leaving uv.lock out of Git | Every clone resolves its own versions | Commit it |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
needs to be updated, but --locked was provided | pyproject.toml changed after the last uv lock | Run uv lock, check the change, and commit both files |
FAQ
What's the difference between --locked and --frozen?
--frozen uses the lock file without checking it. With the same out-of-date lock, uv sync --frozen finished without an error and didn't install tabulate at all, because the lock file didn't list it. --locked stops instead, which is safer.
How do I only check the lock file, without installing?
With uv lock --check. On the out-of-date lock it gave the same error, ending with but --check was provided.
Does uv sync remove packages that aren't in the lock?
Yes. The guide says "uv sync performs "exact" syncing by default, which means it will remove any packages that are not selected for installation."
Conclusion
uv sync --locked rebuilt .venv with exactly humanize 4.17.0 from uv.lock, and refused to run once pyproject.toml no longer matched the lock. Run uv lock after changing dependencies, commit both files, and use --locked wherever an environment must match.
Additional Resources
- Locking and syncing —
--locked,--frozenand exact syncing. - Project structure and files — what
uv.lockis for.
