From c8146cc52b64a9cc02a27ba5f27c5ac33e14c628 Mon Sep 17 00:00:00 2001 From: David de la Iglesia Castro Date: Sat, 17 Oct 2020 11:58:25 +0200 Subject: [PATCH] Skip opencv requirement if it's already installed in the env (i.e. via conda) (#616) * Skip opencv requirement if it's already installed in the env * pre-commit * Check opencv conda version * Check opencv conda version --- setup.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) 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():