From 1a5190f5d73f088e6327a9d80c575f323104c7fb Mon Sep 17 00:00:00 2001 From: liuxiong Date: Thu, 15 Aug 2024 18:45:19 +0800 Subject: [PATCH] fix opencv-python handling to avoid conflict --- WAS_Node_Suite.py | 52 ++++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 30 deletions(-) diff --git a/WAS_Node_Suite.py b/WAS_Node_Suite.py index 400ec98..a42d2fe 100644 --- a/WAS_Node_Suite.py +++ b/WAS_Node_Suite.py @@ -14485,36 +14485,28 @@ def encode(self, clip, text, token_normalization, weight_interpretation, seed=0, cstr('`CLIPTextEncode (BlenderNeko Advanced + NSP)` node enabled under `WAS Suite/Conditioning` menu.').msg.print() # opencv-python-headless handling -if 'opencv-python' in packages() or 'opencv-python-headless' in packages(): - try: - import cv2 - build_info = ' '.join(cv2.getBuildInformation().split()) - if "FFMPEG: YES" in build_info: - if was_config.__contains__('show_startup_junk'): - if was_config['show_startup_junk']: - cstr("OpenCV Python FFMPEG support is enabled").msg.print() - if was_config.__contains__('ffmpeg_bin_path'): - if was_config['ffmpeg_bin_path'] == "/path/to/ffmpeg": - cstr(f"`ffmpeg_bin_path` is not set in `{WAS_CONFIG_FILE}` config file. Will attempt to use system ffmpeg binaries if available.").warning.print() - else: - if was_config.__contains__('show_startup_junk'): - if was_config['show_startup_junk']: - cstr(f"`ffmpeg_bin_path` is set to: {was_config['ffmpeg_bin_path']}").msg.print() - else: - cstr(f"OpenCV Python FFMPEG support is not enabled\033[0m. OpenCV Python FFMPEG support, and FFMPEG binaries is required for video writing.").warning.print() - except ImportError: - cstr("OpenCV Python module cannot be found. Attempting install...").warning.print() - install_package( - package='opencv-python-headless[ffmpeg]', - uninstall_first=['opencv-python', 'opencv-python-headless[ffmpeg]'] - ) - try: - import cv2 - cstr("OpenCV Python installed.").msg.print() - except ImportError: - cstr("OpenCV Python module still cannot be imported. There is a system conflict.").error.print() -else: - install_package('opencv-python-headless[ffmpeg]') +try: + import cv2 + build_info = ' '.join(cv2.getBuildInformation().split()) + if "FFMPEG: YES" in build_info: + if was_config.__contains__('show_startup_junk'): + if was_config['show_startup_junk']: + cstr("OpenCV Python FFMPEG support is enabled").msg.print() + if was_config.__contains__('ffmpeg_bin_path'): + if was_config['ffmpeg_bin_path'] == "/path/to/ffmpeg": + cstr(f"`ffmpeg_bin_path` is not set in `{WAS_CONFIG_FILE}` config file. Will attempt to use system ffmpeg binaries if available.").warning.print() + else: + if was_config.__contains__('show_startup_junk'): + if was_config['show_startup_junk']: + cstr(f"`ffmpeg_bin_path` is set to: {was_config['ffmpeg_bin_path']}").msg.print() + else: + cstr(f"OpenCV Python FFMPEG support is not enabled\033[0m. OpenCV Python FFMPEG support, and FFMPEG binaries is required for video writing.").warning.print() +except ImportError: + cstr("OpenCV Python module cannot be found. Attempting install...").warning.print() + install_package( + package='opencv-python-headless[ffmpeg]', + uninstall_first=['opencv-python', 'opencv-python-headless[ffmpeg]'] + ) try: import cv2 cstr("OpenCV Python installed.").msg.print()