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

1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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 it sounds like workarounds are the only option, and this one prevents a lot of manual pip install something something-else

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.