Python setuptools allows you to specify optional dependencies, but does it allow you to do something in the inverse?
For example, let's say I have a list of dependencies in my_package
like below:
So if I installed the package with pip install my_package
, it would also install these two dependencies.
However, for certain use cases, a user may not need pandas
. So I would want to do something like pip install my_package[~pandas]
or something like that to instruct pip to not install pandas.
Is this something that is currently supported?
It is not currently supported - extras are strictly additive. It has been proposed several times, but the discussions never seem to get anywhere.
The latest discussion is here:
Proposal - expanding optional dependencies to support opt-out of recommended/default installables.
As a workaround, you can use:
pip install --no-deps my_package
But this would exclude every dependency, including pandas. You'd have to find and install the other dependencies manually.
As you mentioned, while it is possible to install optional dependencies with, for example
pip install my_package[super,cool]
the opposite, keeping from installing dependencies (!cool
) is not possible. Wim already mentioned the --no-deps
workaround. Another workaround might be to provide two versions, my_package
and my_package_vanilla
with different dependencies. Then user could install, for example:
my_package
to install all default dependencies needed by the average usermy_package_vanilla
to install just the bare bones version of my_package
(perhaps even non-functional without extras?)my_package_vanilla[pandas,super,cool]
installing three sets of extra dependencies chosen by the user.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With