TExcelTAD

uv pip & uv venv

Not every project wants to become a uv project. uv pip is a drop-in, much faster reimplementation of the pip and pip-tools commands you already know, working on any virtual environment. It's the easiest way to adopt uv: change pip install to uv pip install in a Dockerfile or CI script and nothing else.

pip / pip-tools uv
python -m venv .venv uv venv
pip install -r requirements.txt uv pip install -r requirements.txt
pip-compile requirements.in uv pip compile requirements.in -o requirements.txt
pip-sync requirements.txt uv pip sync requirements.txt
pip freeze, pip list, pip show uv pip freeze, uv pip list, uv pip show
pipdeptree uv pip tree
pip check uv pip check

Which environment does it use?

pip installs into the environment it belongs to. uv lives outside every environment, so it has to pick one: the active environment ($VIRTUAL_ENV), else a .venv in the current or a parent directory, else --python <path>. It refuses to install into the system Python unless you pass --system:

bash · try it yourself
uv pip install attrs 2>&1
echo "---"
uv venv -q
uv pip install attrs==26.1.0 2>&1
uv pip list
error: No virtual environment found; run `uv venv` to create an environment, or pass `--system` to install into a non-virtual environment
---
Resolved 1 package in 9ms
Prepared 1 package in 4ms
Installed 1 package in 17ms
 + attrs==26.1.0
Package Version
------- -------
attrs   26.1.0

No activation was needed: uv found .venv in the current directory.

The pip-tools workflow

The pip-tools idea is the best way to manage plain requirements files: write the direct dependencies loosely in requirements.in, compile them into a fully pinned requirements.txt (the lockfile), and sync environments to it.

bash · try it yourself
cat > requirements.in <<'TXT'
requests>=2.31
rich
TXT
uv pip compile requirements.in -o requirements.txt 2>&1
echo "--- $(grep -c '==' requirements.txt) pinned lines written to requirements.txt"
Resolved 9 packages in 58ms
# This file was autogenerated by uv via the following command:
#    uv pip compile requirements.in -o requirements.txt
certifi==2026.10.23
    # via requests
charset-normalizer==3.5.2
    # via requests
idna==3.20
    # via requests
markdown-it-py==4.2.0
    # via rich
mdurl==0.1.2
    # via markdown-it-py
pygments==2.21.0
    # via rich
requests==2.34.2
    # via -r requirements.in
rich==15.0.0
    # via -r requirements.in
urllib3==2.8.0
    # via requests
--- 9 pinned lines written to requirements.txt

uv prints the result and writes it to the -o file. The # via comments keep what pip freeze throws away: why each package is there. Each line is pinned with ==, transitive ones included. Commit both files.

Then make an environment match the compiled file exactly; uv pip sync installs what's missing and removes everything else:

bash · try it yourself
printf 'requests==2.31.0\ncertifi==2026.10.23\ncharset-normalizer==3.5.2\nidna==3.20\nurllib3==2.8.0\n' > requirements.txt
uv venv -q
uv pip install -q attrs
uv pip sync requirements.txt 2>&1
uv pip freeze
Resolved 5 packages in 20ms
Prepared 5 packages in 16ms
Uninstalled 1 package in 1ms
Installed 5 packages in 17ms
 - attrs==26.1.0
 + certifi==2026.10.23
 + charset-normalizer==3.5.2
 + idna==3.20
 + requests==2.31.0
 + urllib3==2.8.0
certifi==2026.10.23
charset-normalizer==3.5.2
idna==3.20
requests==2.31.0
urllib3==2.8.0

Pinning to older versions and constraints

uv pip compile accepts constraints (-c), overrides, and the useful --upgrade-package to bump one dependency in an existing requirements.txt while keeping the rest:

bash · try it yourself
printf 'requests>=2.31\nrich\n' > requirements.in
printf 'requests==2.31.0\nrich==13.9.4\n' > constraints.txt
uv pip compile -q requirements.in -c constraints.txt -o requirements.txt
grep -E '^(requests|rich)' requirements.txt
echo "--- later: allow rich to move, keep requests"
uv pip compile -q requirements.in -o requirements.txt --upgrade-package rich
grep -E '^(requests|rich)' requirements.txt
requests==2.31.0
rich==13.9.4
--- later: allow rich to move, keep requests
requests==2.31.0
rich==15.0.0

The second compile kept requests==2.31.0 from the existing output file even though 2.34.2 exists: like pip-compile, uv treats an existing requirements.txt as preferences, so recompiling never upgrades by surprise.

Compatibility notes

uv pip is close to pip but deliberately not identical; the uv docs list the differences. The ones you'll meet first:

  • No pip inside uv venv environments (see venv vs virtualenv vs uv venv).
  • When several indexes are configured, uv takes a package from the first index that has it (protection against dependency confusion), where pip merges all indexes.
  • Build isolation, caching and downloads are uv's own; --no-build-isolation exists but needs the build backend already in the environment.
  • uv pip compile resolves for the current platform unless you pass --universal.

Test yourself

Where does uv pip install attrs install when no environment is active?

  1. Into the system Python
  2. Into a .venv in the current or a parent directory; without one it errors unless --system is given
  3. Into ~/.local
  4. Into uv's cache

What's the difference between uv pip install -r requirements.txt and uv pip sync requirements.txt?

  1. None
  2. sync also removes packages not listed, making the environment match exactly
  3. sync is slower
  4. install updates the file

In the pip-tools workflow, which file do you edit by hand?

  1. requirements.txt
  2. requirements.in (direct dependencies); requirements.txt is generated
  3. Both
  4. Neither