From 2daccd995d8c7e22e6af93bf7c433b2074097aff Mon Sep 17 00:00:00 2001 From: Chenlei Hu Date: Wed, 9 Aug 2023 22:06:52 -0400 Subject: [PATCH] :bug: Add dependency on opencv 4.8.0 (#1899) adding -U to pip --- install.py | 22 ++++++++++++++++++++-- requirements.txt | 1 + 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/install.py b/install.py index abbce3e4f..9046cd19f 100644 --- a/install.py +++ b/install.py @@ -1,18 +1,36 @@ import launch import os import pkg_resources +from typing import Tuple, Optional req_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "requirements.txt") + +def comparable_version(version: str) -> Tuple: + return tuple(version.split('.')) + + +def get_installed_version(package: str) -> Optional[str]: + try: + return pkg_resources.get_distribution(package).version + except Exception: + return None + + with open(req_file) as file: for package in file: try: package = package.strip() if '==' in package: package_name, package_version = package.split('==') - installed_version = pkg_resources.get_distribution(package_name).version + installed_version = get_installed_version(package_name) if installed_version != package_version: - launch.run_pip(f"install {package}", f"sd-webui-controlnet requirement: changing {package_name} version from {installed_version} to {package_version}") + launch.run_pip(f"install -U {package}", f"sd-webui-controlnet requirement: changing {package_name} version from {installed_version} to {package_version}") + elif '>=' in package: + package_name, package_version = package.split('>=') + installed_version = get_installed_version(package_name) + if not installed_version or comparable_version(installed_version) < comparable_version(package_version): + launch.run_pip(f"install -U {package}", f"sd-webui-controlnet requirement: changing {package_name} version from {installed_version} to {package_version}") elif not launch.is_installed(package): launch.run_pip(f"install {package}", f"sd-webui-controlnet requirement: {package}") except Exception as e: diff --git a/requirements.txt b/requirements.txt index 573936d8c..f9f438aba 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ mediapipe svglib fvcore +opencv-python>=4.8.0