diff --git a/setup.py b/setup.py index 1888694e3..7a6071dae 100644 --- a/setup.py +++ b/setup.py @@ -119,12 +119,21 @@ def parse_requirements(fname='requirements.txt', with_version=True): return packages -# If first not installed install second package -CHOOSE_INSTALL_REQUIRES = [('opencv-python-headless>=3', 'opencv-python>=3')] - install_requires = parse_requirements() -for main, secondary in CHOOSE_INSTALL_REQUIRES: - install_requires.append(choose_requirement(main, secondary)) + +try: + # OpenCV installed via conda. + import cv2 # NOQA: F401 + major, minor, *rest = cv2.__version__.split('.') + if int(major) < 3: + raise RuntimeError( + f'OpenCV >=3 is required but {cv2.__version__} is installed') +except ImportError: + # If first not installed install second package + CHOOSE_INSTALL_REQUIRES = [('opencv-python-headless>=3', + 'opencv-python>=3')] + for main, secondary in CHOOSE_INSTALL_REQUIRES: + install_requires.append(choose_requirement(main, secondary)) def get_extensions():