5

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.)

Linuxios
  • 34,849
  • 13
  • 91
  • 116
  • Apparently this has been discussed at length on python forums: https://discuss.python.org/t/adding-a-default-extra-require-environment/4898 – Linuxios Apr 19 '21 at 17:35

1 Answers1

1

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.

Olivier V
  • 93
  • 5
  • This is not a bad idea — I would have prefered something that works in one line with `pip install` (even from PyPI), but given [discussion on Python forums](https://discuss.python.org/t/adding-a-default-extra-require-environment/4898) it sounds like workarounds are the only option, and this one prevents a lot of manual `pip install something something-else` – Linuxios Apr 19 '21 at 17:36