I have Python projects that are applications or scripts rather than packages I want to install. What does pip's --only-deps option change, and how does it compare with other ways to handle dependencies?
How do you manage dependencies for a Python app without installing the app itself?
Answers
pip install --only-deps . is meant to install the current project's dependencies without installing the project itself. That lets an app keep its dependency declarations in pyproject.toml without needing a separate workaround just to skip the app installation.
It's a pip 26.2 feature, so check the pip version in your environment before relying on the flag.
Reply to this answer
This looks especially handy for container builds. You can separate dependency installation from the rest of the app setup and avoid custom scripts that split those steps. It can also help with caching the dependency layer when the dependency inputs haven't changed.
Reply to this answer
If you already use uv, uv sync --no-install-project addresses a similar need. The pip option is useful if you'd rather stick with pip instead of adding another tool, but it isn't necessarily a reason to change an existing uv workflow.
Reply to this answer
For a standalone script, another option is uv run --with followed by the dependencies and the script. That's a different workflow, though. You're specifying dependencies on the command line rather than installing the dependencies declared by a project.
Reply to this answer
Add your answer
Answers are reviewed before publication.
3g+notebook_581:
The cache benefit still depends on how the build is arranged. Changes to files used by that install step can invalidate the layer.