Skip to content

Allow pip install to only install optional dependencies #12191

Closed
@mwtoews

Description

@mwtoews

What's the problem this feature will solve?

It seems there is a need to allow pip to install optional dependencies (or extras) independent from a package installation. For instance, packages use stand-alone requirements files that can simply be installed e.g.:

pip install -r requirements-test.txt

However, if these optional dependencies are migrated into a static pyproject.toml file following PEP 621, there is no equivalent to install only test dependencies.

Describe the solution you'd like

Unsure what solution would be best, but here are some suggestions:

# using a command option
pip install mypackage[test] --only-extras

# using syntax
pip install !mypackage[test]

Alternative Solutions

Install/uninstall method

Using the above example, install the package + test, then uninstall the package with two commands:

pip install mypackage[test]
pip uninstall mypackage

But there is obvious overhead to install the package (+ dependencies) then uninstall the package (without dependencies).

Copy/paste method

This method needs access to the sdist or source repository. Locate the source file where optional dependencies are declared, which may vary within pyproject.toml, python.cfg, python.py or dynamically loaded from another file. Copy and paste entries into a pip install ... command. This is often the quickest solution where there are only a few dependencies.

Duplicate requirements files method

Projects may duplicate their optional dependencies in requirements files. This can be manually maintained to mirror the information, or (e.g.) kept in sync with create a pre-commit script to generate requirements files.

Additional context

N/A

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions