imgaug: Explicit OpenCV flavor requirement conflicts with existing installs of OpenCV
The current practice of specifying a requirement for opencv-python-headless causes conflicts for other installations of OpenCV. For example, if a user requires modules from opencv-contrib-python that are not available in opencv-python-headless but they install imgaug, pip will install both versions and thusly have conflicting versions of OpenCV with different features. To do this, I have to do:
pip install imgaug
pip uninstall -y opencv-python-headless
pip install opencv-contrib-python-headless
It seems this problem was contemplated in https://github.com/aleju/imgaug/pull/324 so I suppose I’m just here to confirm those fears are well-founded.
From what I can tell, imgaug supports any of the four opencv-*-python-* flavors. In light of that, I humbly propose the following as options (with a preference for the first):
- Removing
opencv-*-*from theinstall_requiresinsetup.py. This is the simplest option and is compatible with the current installation instructions in the README which ask the user to install OpenCV on their own first. It is at this point that the user could choose the OpenCV flavor that makes sense for their application. - Implementing more logic to check for existing OpenCV versions. I think this will be kind of a pain but is what
scikit-imageseems to do and it may create problems for people who use package management systems likepipenvorpoetrywhere package installation sequence is ill-defined. It also will have sequencing issues for users who build their own customized versions ofopencv-pythonin order to use non-free algorithms in OpenCV.
I will gladly submit a PR for this if the relevant folks agree this is okay. Thanks!
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 6
- Comments: 20 (1 by maintainers)
pip install --upgrade pipHave a try.As far as I can tell, the modification to
setup.pyworks great when installingimgaugfrom source but doesn’t help when installing the the pypi wheel. I’m guessing this is because the wheel METADATA forimgaug0.4.0 hasRequires-Dist: opencv-python.Specifically, if I run
pip install opencv-python-headless imgaug, I end up with bothopencv-pythonandopencv-python-headless:I couldn’t find a way list alternative dependencies in a wheel, and it appears the idea was considered and rejected in PEP 426.
@aleju, I can also confirm that the uploaded wheel triggers the
opencv-pythondependency (as opposed toopencv-python-headless). I think this could be resolved by either of the following two things:opencv-python-headless) is referenced in itWould that be feasible?
I second that.
As a workaround (besides holding at
0.3.0) one can simply avoid the binary/wheel method for imgaug, as in:…or in a
requirements.txtfile…And there is yet another option: I have created a pseudo-package re-branding
opencv-python-headlessasopencv-python(and trying to re-export its install-time version number, too). Thus, you could install this package prior to installing some dependency chain to avoid dragging inopencv-pythonproper (and thereby replacing headless).I wonder, though, why the OpenCV Python bindings did not decide to solve the contrib and X11 options via the
extrasmechanism. So packages which depend on these features could depend onopencv-python[contrib]oropencv[contrib,x11], or in turn make them conditional in extras of their own (e.g.extras_require={'plot':['opencv-python[x11]']})…It seems like @aleju stopped working on GitHub around June last year. If he doesn’t intend to (exclusively) continue maintaining this repo, maybe someone can offer a helping hand 🤔. I opened #764 for that matter. Let’s discuss over there. If Alex doesn’t respond in say a month, I can for sure give him a call 😉.
I have also encountered this issue where we are trying to break the dependency on
opencv-python(i.e. the non-headless version), but it makes its way in due toalbumentations==0.4.6 -> imgaug==0.4.0.I’m no Python packaging expert, but It seems like the wheel was made in an environment where
opencv-pythonwas installed so it made its way into the wheel dependencies. Can we get a new wheel withopencv-python-headless, please?In some projects (e.g. paddleOCR), there is
imgaugin the “requirements.txt” file. Is there any convenient method to replace it with albumentations? @patzmYo apparently the recent release
v1.0.0ofalbumentationsavoids this issue. Check out the release notes: https://github.com/albumentations-team/albumentations/releases/tag/1.0.0IINM, that could be as simple as:
Anyone with the credentials for imgaug on PyPI could do that.
Yes, a true post-release according to PEP 440 (like
0.4.0.post1) would probably be better.Can you quickly elaborate what changed?
No, this doesn’t give us a way to
pip install imgaug==0.4without it installingopencv-python(which we don’t want). We’ve pinned our package to requireimgaug==0.3.0so that we can useopencv-python-headless.