# Conditional package install depending on other packages in environment

**URL:** <https://discuss.python.org/t/conditional-package-install-depending-on-other-packages-in-environment/4140>\
**Category:** Packaging\
**Created:** [May 9, 2020, 1:45pm UTC](https://discuss.python.org/t/conditional-package-install-depending-on-other-packages-in-environment/4140 "2020-05-09T13:45:31Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![dcnieho](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/dcnieho/32/10220_2.png) [@dcnieho](https://discuss.python.org/u/dcnieho)\
**Post date:** [December 17, 2022, 12:42pm UTC](https://discuss.python.org/t/conditional-package-install-depending-on-other-packages-in-environment/4140/4 "2022-12-17T12:42:55Z")

</div>

Here’s another use case for supporting `Provides-Dist` (and `Obsoletes-Dist`):

> <https://github.com/opencv/opencv-python/issues/677>
>
> Hey guys! A bit confused on how to properly set a PIP dependency for my package …if it depends on OpenCV. README clearly states:
> 
> \> There are four different packages (see options 1, 2, 3 and 4 below) and you should SELECT ONLY ONE OF THEM.
> 
> implying
> opencv-python
> opencv-contrib-python
> opencv-python-headless
> opencv-contrib-python-headless
> 
> Say I have \`opencv-contrib-python-headless\` installed in my environment, and then I install pip package that depends on \`opencv-python-headless\`. Even though it can perfectly fine work with (and supposed to) \`opencv-contrib-python-headless\`, pip still gonna install \`opencv-python-headless\` breaking aforementioned rule.
> 
> How to handle that? What should that package set as a dependency to install opencv only if neither packages installed

The `opencv-python` packages come in multiple flavors and only one of them should be installed as explicitly stated in their documentation. So if an install already has `opencv-contrib-python` installed, a request to install `opencv-python` (not an uncommon dependency for other packages) should be ignored as its functionality (and more) is already provided by `opencv-contrib-python`. Currently, users can end up in an environment with both `opencv-python` and `opencv-contrib-python` installed, and depending on order of install all kinds of breakage.

Since `opencv-contrib-python` provides a superset of `opencv-python`, being able to specify Obsoletes-Dist and having it honored by the package manager would also be of great use. Then a user or package requesting installation of `opencv-contrib-python` would lead to `opencv-python` being removed. That doesn’t cause a loss of functionality and prevents having more than one of the packages installed at a time, as should really be avoided.

For future reference, see also [this stackoverflow post](https://stackoverflow.com/questions/61603438/do-any-tools-support-provides-dist-metadata-for-python-packages-if-not-why) hinting at how the tensorflow ecosystem could benefit from this.

---

_[View the full topic](https://discuss.python.org/t/conditional-package-install-depending-on-other-packages-in-environment/4140)._
