Optionally exclude some dependencies when `pip install`ing

Viewed 1310

setuptools provides, as is often used, a way to specify optional dependencies with extras_require. Is there a way to do the opposite? That is, to have

pip install mypackage

install a full set of dependencies, but to have something like

pip install mypackage[core]

or

pip install --core-option mypackage

only install a limited set of core dependencies? It doesn’t have to be like extras_require, just some way to specify in the pip install that only core dependencies are required.

(For some packages, breaking backwards compatibility in terms of installation is a difficult choice, especially when most users want all of the dependencies. Nevertheless, some users can need to avoid heavy or broken dependencies that are not required for core functions.)

1 Answers

If a lib is dependent it means your code needs it and cannot work without it so I don't think this is possible with a flag.

So I would keep a requirements.txt in root for the core functionality and an optional-requirements.txt next to it.

Together with a short guide in the readme.md to use pip install requirements.txt to get the core and pip install optional-requirements.txt to get additional stuff that isn't necessary for the code to run. Like better debugging.

I would strongly recommend to put in the readme what's different if you have or have not installed the optional packages.

Related