From b5abf19a1b0726cde69fcbb7f7b592c8ad8e067e Mon Sep 17 00:00:00 2001 From: "Dr.Lt.Data" Date: Sat, 21 Sep 2024 19:27:06 +0900 Subject: [PATCH] remove automatic installation feature --- README.md | 20 +++-- __init__.py | 24 +----- install.py | 176 +-------------------------------------- modules/impact/config.py | 2 +- pyproject.toml | 2 +- requirements.txt | 3 +- 6 files changed, 25 insertions(+), 202 deletions(-) diff --git a/README.md b/README.md index 251a4f2..f017921 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ This custom node helps to conveniently enhance images through Detector, Detailer ## NOTICE +* V7.6: Automatic installation is no longer supported. Please install using ComfyUI-Manager, or manually install requirements.txt and run install.py to complete the installation. * V7.0: Supports Switch based on Execution Model Inversion. * V6.0: Supports FLUX.1 model in Impact KSampler, Detailers, PreviewBridgeLatent * V5.0: It is no longer compatible with versions of ComfyUI before 2024.04.08. @@ -331,6 +332,10 @@ mmdet_skip = False ## Installation +### Install via ComfyUI-Manager (Recommended) +* Search `ComfyUI Impact Pack` in ComfyUI-Manager and click `Install` button. + +### Manual Install (Not Recommended) 1. `cd custom_nodes` 2. `git clone https://github.com/ltdrdata/ComfyUI-Impact-Pack.git` 3. `cd ComfyUI-Impact-Pack` @@ -339,24 +344,29 @@ mmdet_skip = False 5. (optional) `python install.py` * Impact Pack will automatically install its dependencies during its initial launch. * For the portable version, you should execute the command `..\..\..\python_embeded\python.exe install.py` to run the installation script. - - 6. Restart ComfyUI * NOTE1: If an error occurs during the installation process, please refer to [Troubleshooting Page](troubleshooting/TROUBLESHOOTING.md) for assistance. * NOTE2: You can use this colab notebook [colab notebook](https://colab.research.google.com/github/ltdrdata/ComfyUI-Impact-Pack/blob/Main/notebook/comfyui_colab_impact_pack.ipynb) to launch it. This notebook automatically downloads the impact pack to the custom_nodes directory, installs the tested dependencies, and runs it. * NOTE3: If you create an empty file named `skip_download_model` in the `ComfyUI/custom_nodes/` directory, it will skip the model download step during the installation of the impact pack. + ## Package Dependencies (If you need to manual setup.) * pip install - * openmim * segment-anything * ultralytics * scikit-image - * piexif - * (optional) pycocotools + * piexif + * opencv-python + * GitPython + * scipy + * numpy<2 + * dill + * matplotlib * (optional) onnxruntime + * (deprecated) openmim # for mim + * (deprecated) pycocotools # for mim * mim install (deprecated) * mmcv==2.0.0, mmdet==3.0.0, mmengine==0.7.2 diff --git a/__init__.py b/__init__.py index c3eb14b..5603cb8 100644 --- a/__init__.py +++ b/__init__.py @@ -23,22 +23,6 @@ import impact.sample_error_enhancer print(f"### Loading: ComfyUI-Impact-Pack ({impact.config.version})") -def do_install(): - import importlib - spec = importlib.util.spec_from_file_location('impact_install', os.path.join(os.path.dirname(__file__), 'install.py')) - impact_install = importlib.util.module_from_spec(spec) - spec.loader.exec_module(impact_install) - - -# ensure dependency -if not os.path.exists(os.path.join(subpack_path, ".git")) and os.path.exists(subpack_path): - print(f"### CompfyUI-Impact-Pack: corrupted subpack detected.") - shutil.rmtree(subpack_path) - -if impact.config.get_config()['dependency_version'] < impact.config.dependency_version or not os.path.exists(subpack_path): - print(f"### ComfyUI-Impact-Pack: Updating dependencies [{impact.config.get_config()['dependency_version']} -> {impact.config.dependency_version}]") - do_install() - sys.path.append(subpack_path) # Core @@ -63,10 +47,10 @@ try: import mmcv from mmdet.apis import (inference_detector, init_detector) from mmdet.evaluation import get_classes -except: - import importlib - print("### ComfyUI-Impact-Pack: Reinstall dependencies (several dependencies are missing.)") - do_install() +except Exception as e: + import logging + logging.error("[Impact Pack] Failed to import due to several dependencies are missing!!!!") + raise e import impact.impact_server # to load server api diff --git a/install.py b/install.py index f7f2a73..76ff868 100644 --- a/install.py +++ b/install.py @@ -5,7 +5,6 @@ import subprocess import threading import locale import traceback -import re if sys.argv[0] == 'install.py': @@ -13,7 +12,6 @@ if sys.argv[0] == 'install.py': impact_path = os.path.join(os.path.dirname(__file__), "modules") -old_subpack_path = os.path.join(os.path.dirname(__file__), "subpack") subpack_path = os.path.join(os.path.dirname(__file__), "impact_subpack") subpack_repo = "https://github.com/ltdrdata/ComfyUI-Impact-Subpack" @@ -71,64 +69,11 @@ def process_wrap(cmd_str, cwd=None, handler=None, env=None): # --- -pip_list = None - - -def get_installed_packages(): - global pip_list - - if pip_list is None: - try: - result = subprocess.check_output([sys.executable, '-m', 'pip', 'list'], universal_newlines=True) - pip_list = set([line.split()[0].lower() for line in result.split('\n') if line.strip()]) - except subprocess.CalledProcessError as e: - print(f"[ComfyUI-Manager] Failed to retrieve the information of installed pip packages.") - return set() - - return pip_list - - -def is_installed(name): - name = name.strip() - pattern = r'([^<>!=]+)([<>!=]=?)' - match = re.search(pattern, name) - - if match: - name = match.group(1) - - result = name.lower() in get_installed_packages() - return result - - -def is_requirements_installed(file_path): - print(f"req_path: {file_path}") - if os.path.exists(file_path): - with open(file_path, 'r') as file: - lines = file.readlines() - for line in lines: - if not is_installed(line): - return False - - return True - try: import platform - from torchvision.datasets.utils import download_url import impact.config - print("### ComfyUI-Impact-Pack: Check dependencies") - - if "python_embeded" in sys.executable or "python_embedded" in sys.executable: - pip_install = [sys.executable, '-s', '-m', 'pip', 'install'] - pip_upgrade = [sys.executable, '-s', '-m', 'pip', 'install', '-U'] - mim_install = [sys.executable, '-s', '-m', 'mim', 'install'] - else: - pip_install = [sys.executable, '-m', 'pip', 'install'] - pip_upgrade = [sys.executable, '-m', 'pip', 'install', '-U'] - mim_install = [sys.executable, '-m', 'mim', 'install'] - - def ensure_subpack(): import git if os.path.exists(subpack_path): @@ -145,106 +90,11 @@ try: else: git.Repo.clone_from(subpack_repo, subpack_path) - if os.path.exists(old_subpack_path): - shutil.rmtree(old_subpack_path) - - - def ensure_pip_packages_first(): - subpack_req = os.path.join(subpack_path, "requirements.txt") - if os.path.exists(subpack_req) and not is_requirements_installed(subpack_req): - process_wrap(pip_install + ['-r', 'requirements.txt'], cwd=subpack_path) - - if not impact.config.get_config()['mmdet_skip']: - process_wrap(pip_install + ['openmim']) - - try: - import pycocotools - except Exception: - if platform.system() not in ["Windows"] or platform.machine() not in ["AMD64", "x86_64"]: - print(f"Your system is {platform.system()}; !! You need to install 'libpython3-dev' for this step. !!") - - process_wrap(pip_install + ['pycocotools']) - else: - pycocotools = { - (3, 8): "https://github.com/Bing-su/dddetailer/releases/download/pycocotools/pycocotools-2.0.6-cp38-cp38-win_amd64.whl", - (3, 9): "https://github.com/Bing-su/dddetailer/releases/download/pycocotools/pycocotools-2.0.6-cp39-cp39-win_amd64.whl", - (3, 10): "https://github.com/Bing-su/dddetailer/releases/download/pycocotools/pycocotools-2.0.6-cp310-cp310-win_amd64.whl", - (3, 11): "https://github.com/Bing-su/dddetailer/releases/download/pycocotools/pycocotools-2.0.6-cp311-cp311-win_amd64.whl", - } - - version = sys.version_info[:2] - url = pycocotools[version] - process_wrap(pip_install + [url]) - - - def ensure_pip_packages_last(): - my_path = os.path.dirname(__file__) - requirements_path = os.path.join(my_path, "requirements.txt") - - if not is_requirements_installed(requirements_path): - process_wrap(pip_install + ['-r', requirements_path]) - - # fallback - try: - import segment_anything - from skimage.measure import label, regionprops - import piexif - except Exception: - process_wrap(pip_install + ['-r', requirements_path]) - - # !! cv2 importing test must be very last !! - try: - from cv2 import setNumThreads - except Exception: - try: - is_open_cv_installed = False - - # upgrade if opencv is installed already - if is_installed('opencv-python'): - process_wrap(pip_upgrade + ['opencv-python']) - is_open_cv_installed = True - - if is_installed('opencv-python-headless'): - process_wrap(pip_upgrade + ['opencv-python-headless']) - is_open_cv_installed = True - - if is_installed('opencv-contrib-python'): - process_wrap(pip_upgrade + ['opencv-contrib-python']) - is_open_cv_installed = True - - if is_installed('opencv-contrib-python-headless'): - process_wrap(pip_upgrade + ['opencv-contrib-python-headless']) - is_open_cv_installed = True - - # if opencv is not installed install `opencv-python-headless` - if not is_open_cv_installed: - process_wrap(pip_install + ['opencv-python-headless']) - except: - print(f"[ERROR] ComfyUI-Impact-Pack: failed to install 'opencv-python'. Please, install manually.") - - def ensure_mmdet_package(): - try: - import mmcv - import mmdet - from mmdet.evaluation import get_classes - except Exception: - process_wrap(pip_install + ['opendatalab==0.0.9']) - process_wrap(pip_install + ['-U', 'openmim']) - process_wrap(mim_install + ['mmcv>=2.0.0rc4, <2.1.0']) - process_wrap(mim_install + ['mmdet==3.0.0']) - process_wrap(mim_install + ['mmengine==0.7.4']) - def install(): subpack_install_script = os.path.join(subpack_path, "install.py") print(f"### ComfyUI-Impact-Pack: Updating subpack") - try: - import git - except Exception: - if not is_installed('GitPython'): - process_wrap(pip_install + ['GitPython']) - ensure_subpack() # The installation of the subpack must take place before ensure_pip. cv2 triggers a permission error. new_env = os.environ.copy() @@ -253,37 +103,16 @@ try: if os.path.exists(subpack_install_script): process_wrap([sys.executable, 'install.py'], cwd=subpack_path, env=new_env) - if not is_requirements_installed(os.path.join(subpack_path, 'requirements.txt')): - process_wrap(pip_install + ['-r', 'requirements.txt'], cwd=subpack_path) else: print(f"### ComfyUI-Impact-Pack: (Install Failed) Subpack\nFile not found: `{subpack_install_script}`") - ensure_pip_packages_first() - - if not impact.config.get_config()['mmdet_skip']: - ensure_mmdet_package() - - ensure_pip_packages_last() - # Download model print("### ComfyUI-Impact-Pack: Check basic models") - bbox_path = os.path.join(model_path, "mmdets", "bbox") sam_path = os.path.join(model_path, "sams") onnx_path = os.path.join(model_path, "onnx") - if not os.path.exists(os.path.join(os.path.dirname(__file__), '..', 'skip_download_model')): - if not os.path.exists(bbox_path): - os.makedirs(bbox_path) - - if not impact.config.get_config()['mmdet_skip']: - if not os.path.exists(os.path.join(bbox_path, "mmdet_anime-face_yolov3.pth")): - download_url("https://huggingface.co/dustysys/ddetailer/resolve/main/mmdet/bbox/mmdet_anime-face_yolov3.pth", bbox_path) - - if not os.path.exists(os.path.join(bbox_path, "mmdet_anime-face_yolov3.py")): - download_url("https://raw.githubusercontent.com/Bing-su/dddetailer/master/config/mmdet_anime-face_yolov3.py", bbox_path) - - if not os.path.exists(os.path.join(sam_path, "sam_vit_b_01ec64.pth")): - download_url("https://dl.fbaipublicfiles.com/segment_anything/sam_vit_b_01ec64.pth", sam_path) + if not os.path.exists(sam_path): + os.makedirs(sam_path) if not os.path.exists(onnx_path): print(f"### ComfyUI-Impact-Pack: onnx model directory created ({onnx_path})") @@ -291,7 +120,6 @@ try: impact.config.write_config() - install() except Exception as e: diff --git a/modules/impact/config.py b/modules/impact/config.py index 68882e7..b0bba60 100644 --- a/modules/impact/config.py +++ b/modules/impact/config.py @@ -1,7 +1,7 @@ import configparser import os -version_code = [7, 5, 3] +version_code = [7, 6] version = f"V{version_code[0]}.{version_code[1]}" + (f'.{version_code[2]}' if len(version_code) > 2 else '') dependency_version = 22 diff --git a/pyproject.toml b/pyproject.toml index 79296c3..5d72a53 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "comfyui-impact-pack" description = "This extension offers various detector nodes and detailer nodes that allow you to configure a workflow that automatically enhances facial details. And provide iterative upscaler." -version = "7.5.3" +version = "7.6" license = { file = "LICENSE.txt" } dependencies = ["segment-anything", "scikit-image", "piexif", "transformers", "opencv-python-headless", "GitPython", "scipy>=1.11.4"] diff --git a/requirements.txt b/requirements.txt index 9cc443e..0066b6d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,5 @@ opencv-python-headless GitPython scipy>=1.11.4 numpy<2 -dill \ No newline at end of file +dill +matplotlib \ No newline at end of file