Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python setuptools exclude dependencies when installing

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:

  • numpy
  • pandas

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?

like image 829
pythonweb Avatar asked Sep 05 '25 03:09

pythonweb


2 Answers

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.

like image 120
wim Avatar answered Sep 07 '25 17:09

wim


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 user
  • my_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.
like image 34
np8 Avatar answered Sep 07 '25 15:09

np8