Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkgutil.ImpImporter is deprecated, and Python 3.12 no longer supports this functionality #63

Open
158zd opened this issue Nov 27, 2024 · 2 comments

Comments

@158zd
Copy link

158zd commented Nov 27, 2024

(.venv) PS D:\AI\ComfyUI> python main.py
[START] Security scan
[DONE] Security scan

ComfyUI-Manager: installing dependencies done.

** ComfyUI startup time: 2024-11-27 19:43:50.481212
** Platform: Windows
** Python version: 3.12.7 | packaged by Anaconda, Inc. | (main, Oct 4 2024, 13:17:27) [MSC v.1929 64 bit (AMD64)]
** Python executable: D:\AI\ComfyUI.venv\Scripts\python.exe
** ComfyUI Path: D:\AI\ComfyUI
** Log path: D:\AI\ComfyUI\comfyui.log

Prestartup times for custom nodes:
0.0 seconds: D:\AI\ComfyUI\custom_nodes\rgthree-comfy
0.0 seconds: D:\AI\ComfyUI\custom_nodes\ComfyUI-Easy-Use
10.4 seconds: D:\AI\ComfyUI\custom_nodes\ComfyUI-Manager

Total VRAM 8188 MB, total RAM 65416 MB
pytorch version: 2.5.1+cu124
Set vram state to: NORMAL_VRAM
Device: cuda:0 NVIDIA GeForce RTX 4060 : cudaMallocAsync
Using pytorch cross attention
[Prompt Server] web root: D:\AI\ComfyUI\web
Adding D:\AI\ComfyUI\custom_nodes to sys.path
Traceback (most recent call last):
File "D:\AI\ComfyUI\nodes.py", line 2027, in load_custom_node
module_spec.loader.exec_module(module)
File "", line 995, in exec_module
File "", line 488, in call_with_frames_removed
File "D:\AI\ComfyUI\custom_nodes\comfyui-art-venture_init
.py", line 13, in
from .modules.nodes import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
File "D:\AI\ComfyUI\custom_nodes\comfyui-art-venture\modules\nodes.py", line 12, in
from .utility_nodes import (
File "D:\AI\ComfyUI\custom_nodes\comfyui-art-venture\modules\utility_nodes.py", line 17, in
from .utils import pil2tensor, tensor2pil, ensure_package, get_dict_attribute
File "D:\AI\ComfyUI\custom_nodes\comfyui-art-venture\modules\utils.py", line 9, in
import pkg_resources
File "D:\AI\ComfyUI.venv\Lib\site-packages\pkg_resources_init_.py", line 2191, in
register_finder(pkgutil.ImpImporter, find_on_path)
^^^^^^^^^^^^^^^^^^^
AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'?

Cannot import D:\AI\ComfyUI\custom_nodes\comfyui-art-venture module for custom nodes: module 'pkgutil' has no attribute 'ImpImporter'
[ComfyUI-Easy-Use] server: v1.2.5 Loaded
[ComfyUI-Easy-Use] web root: D:\AI\ComfyUI\custom_nodes\ComfyUI-Easy-Use\web_version/v2 Loaded
Total VRAM 8188 MB, total RAM 65416 MB
pytorch version: 2.5.1+cu124
Set vram state to: NORMAL_VRAM
Device: cuda:0 NVIDIA GeForce RTX 4060 : cudaMallocAsync

Loading: ComfyUI-Impact-Pack (V7.12)

Loading: ComfyUI-Impact-Pack (Subpack: V0.8)

[Impact Pack] Wildcards loading done.
D:\AI\ComfyUI.venv\Lib\site-packages\timm\models\layers_init_.py:48: FutureWarning: Importing from timm.models.layers is deprecated, please import via timm.layers
warnings.warn(f"Importing from {name} is deprecated, please import via timm.layers", FutureWarning)
theUpsiders Logic Nodes: Loaded

Loading: ComfyUI-Manager (V2.52.1)

ComfyUI Revision: 2865 [497db621] | Released on '2024-11-26'

[ComfyUI-Manager] default cache updated: https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/model-list.json
[ComfyUI-Manager] default cache updated: https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/alter-list.json
[ComfyUI-Manager] default cache updated: https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/custom-node-list.json
[ComfyUI-Manager] default cache updated: https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/github-stats.json
[ComfyUI-Manager] default cache updated: https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/extension-node-map.json

Mixlab Nodes: Loaded

json_repair## OK
ChatGPT.available True
edit_mask.available True
ClipInterrogator.available True
PromptGenerate.available True
ChinesePrompt.available True
RembgNode_.available True
TripoSR.available
MiniCPMNode.available
Scenedetect.available
FishSpeech.available
SenseVoice.available
Whisper.available False
fal-client## OK
FalVideo.available

[ReActor] - STATUS - Running v0.5.2-a1 in ComfyUI
Torch version: 2.5.1+cu124
no module 'xformers'. Processing without...
no module 'xformers'. Processing without...
here: D:\AI\ComfyUI\custom_nodes\ComfyUI-tbox
Using ckpts path: D:\AI\ComfyUI\custom_nodes\ComfyUI-tbox....\models\annotator
Using symlinks: False
Using ort providers: ['CUDAExecutionProvider', 'DirectMLExecutionProvider', 'OpenVINOExecutionProvider', 'ROCMExecutionProvider', 'CPUExecutionProvider']
DWPose: Onnxruntime with acceleration providers detected
(pysssss:WD14Tagger) [DEBUG] Available ORT providers: TensorrtExecutionProvider, CUDAExecutionProvider, CPUExecutionProvider
(pysssss:WD14Tagger) [DEBUG] Using ORT providers: CUDAExecutionProvider, CPUExecutionProvider

Comfyroll Studio v1.76 : 175 Nodes Loaded

** For changes, please see patch notes at https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes/blob/main/Patch_Notes.md
** For help, please see the wiki at https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes/wiki

[comfyui_controlnet_aux] | INFO -> Using ckpts path: D:\AI\ComfyUI\custom_nodes\comfyui_controlnet_aux\ckpts
[comfyui_controlnet_aux] | INFO -> Using symlinks: False
[comfyui_controlnet_aux] | INFO -> Using ort providers: ['CUDAExecutionProvider', 'DirectMLExecutionProvider', 'OpenVINOExecutionProvider', 'ROCMExecutionProvider', 'CPUExecutionProvider', 'CoreMLExecutionProvider']
[comfy_mtb] | INFO -> loaded 88 nodes successfuly
[comfy_mtb] | INFO -> Some nodes (2) could not be loaded. This can be ignored, but go to http://127.0.0.1:8188/mtb if you want more information.
Efficiency Nodes: Attempting to add Control Net options to the 'HiRes-Fix Script' Node (comfyui_controlnet_aux add-on)...Success!

[rgthree-comfy] Loaded 42 extraordinary nodes. 🎉

WAS Node Suite: BlenderNeko's Advanced CLIP Text Encode found, attempting to enable CLIPTextEncode support.
WAS Node Suite: CLIPTextEncode (BlenderNeko Advanced + NSP) node enabled under WAS Suite/Conditioning menu.
WAS Node Suite: OpenCV Python FFMPEG support is enabled
WAS Node Suite: ffmpeg_bin_path is set to: D:/AI/wb/ffmpeg/bin/ffmpeg.exe
WAS Node Suite: Finished. Loaded 219 nodes successfully.

    "Do not wait for the opportunity. Create it." - George Bernard Shaw

Import times for custom nodes:
0.0 seconds: D:\AI\ComfyUI\custom_nodes\websocket_image_save.py
0.0 seconds: D:\AI\ComfyUI\custom_nodes\AIGODLIKE-COMFYUI-TRANSLATION
0.0 seconds: D:\AI\ComfyUI\custom_nodes\Batch-Condition-ComfyUI
0.0 seconds: D:\AI\ComfyUI\custom_nodes\ComfyUI-IC-Light-Native
0.0 seconds: D:\AI\ComfyUI\custom_nodes\ComfyUI-Logic
0.0 seconds: D:\AI\ComfyUI\custom_nodes\ComfyUI_ADV_CLIP_emb
0.0 seconds: D:\AI\ComfyUI\custom_nodes\ComfyUI_HF_Servelress_Inference
0.0 seconds: D:\AI\ComfyUI\custom_nodes\ComfyUI-WD14-Tagger
0.0 seconds: D:\AI\ComfyUI\custom_nodes\ComfyUI_IPAdapter_plus
0.0 seconds: D:\AI\ComfyUI\custom_nodes\Comfyui_CXH_joy_caption
0.0 seconds: D:\AI\ComfyUI\custom_nodes\comfyui-inpaint-nodes
0.0 seconds: D:\AI\ComfyUI\custom_nodes\ComfyUI-Custom-Scripts
0.0 seconds: D:\AI\ComfyUI\custom_nodes\comfy-image-saver
0.0 seconds: D:\AI\ComfyUI\custom_nodes\comfyui-various
0.0 seconds: D:\AI\ComfyUI\custom_nodes\ComfyUI_UltimateSDUpscale
0.0 seconds: D:\AI\ComfyUI\custom_nodes\ComfyUI-Florence2
0.0 seconds: D:\AI\ComfyUI\custom_nodes\ComfyUI_essentials
0.0 seconds: D:\AI\ComfyUI\custom_nodes\Derfuu_ComfyUI_ModdedNodes
0.0 seconds: D:\AI\ComfyUI\custom_nodes\ComfyUI_CatVTON_Wrapper
0.0 seconds: D:\AI\ComfyUI\custom_nodes\ComfyUI-KJNodes
0.0 seconds: D:\AI\ComfyUI\custom_nodes\rgthree-comfy
0.1 seconds: D:\AI\ComfyUI\custom_nodes\efficiency-nodes-comfyui
0.1 seconds: D:\AI\ComfyUI\custom_nodes\ComfyUI-IC-Light
0.1 seconds: D:\AI\ComfyUI\custom_nodes\ComfyUI_Comfyroll_CustomNodes
0.1 seconds: D:\AI\ComfyUI\custom_nodes\ComfyUI_InstantID
0.1 seconds: D:\AI\ComfyUI\custom_nodes\comfyui_controlnet_aux
0.1 seconds: D:\AI\ComfyUI\custom_nodes\ComfyUI-Impact-Pack
0.1 seconds (IMPORT FAILED): D:\AI\ComfyUI\custom_nodes\comfyui-art-venture
0.1 seconds: D:\AI\ComfyUI\custom_nodes\comfy_mtb
0.2 seconds: D:\AI\ComfyUI\custom_nodes\comfyui_segment_anything
0.2 seconds: D:\AI\ComfyUI\custom_nodes\Comfyui-ergouzi-Nodes
0.3 seconds: D:\AI\ComfyUI\custom_nodes\ComfyUI_LayerStyle
0.4 seconds: D:\AI\ComfyUI\custom_nodes\comfyui-reactor-node
0.4 seconds: D:\AI\ComfyUI\custom_nodes\comfyui-ollama
0.8 seconds: D:\AI\ComfyUI\custom_nodes\ComfyUI-VideoHelperSuite
0.9 seconds: D:\AI\ComfyUI\custom_nodes\ComfyUI-tbox
0.9 seconds: D:\AI\ComfyUI\custom_nodes\ComfyUI-BrushNet
0.9 seconds: D:\AI\ComfyUI\custom_nodes\ComfyUI-SUPIR
1.0 seconds: D:\AI\ComfyUI\custom_nodes\ComfyUI-Easy-Use
1.2 seconds: D:\AI\ComfyUI\custom_nodes\ComfyUI-Manager
1.2 seconds: D:\AI\ComfyUI\custom_nodes\ComfyUI-AdvancedLivePortrait
3.4 seconds: D:\AI\ComfyUI\custom_nodes\ComfyUI-Inspyrenet-Rembg
5.5 seconds: D:\AI\ComfyUI\custom_nodes\was-node-suite-comfyui
6.2 seconds: D:\AI\ComfyUI\custom_nodes\comfyui-mixlab-nodes

Starting server

To see the GUI go to: http://127.0.0.1:8188

@Romanio1997
Copy link

File "C:\pinokio\ComfyUI_windows_portable\ComfyUI\nodes.py", line 2089, in load_custom_node
module_spec.loader.exec_module(module)
File "", line 995, in exec_module
File "", line 488, in call_with_frames_removed
File "C:\pinokio\ComfyUI_windows_portable\ComfyUI\custom_nodes\comfyui-art-venture_init
.py", line 13, in
from .modules.nodes import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
File "C:\pinokio\ComfyUI_windows_portable\ComfyUI\custom_nodes\comfyui-art-venture\modules\nodes.py", line 12, in
from .utility_nodes import (
File "C:\pinokio\ComfyUI_windows_portable\ComfyUI\custom_nodes\comfyui-art-venture\modules\utility_nodes.py", line 17, in
from .utils import pil2tensor, tensor2pil, ensure_package, get_dict_attribute
File "C:\pinokio\ComfyUI_windows_portable\ComfyUI\custom_nodes\comfyui-art-venture\modules\utils.py", line 9, in
import pkg_resources
File "C:\pinokio\ComfyUI_windows_portable\python_embeded\Lib\site-packages\pkg_resources_init_.py", line 2191, in
register_finder(pkgutil.ImpImporter, find_on_path)
^^^^^^^^^^^^^^^^^^^
AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'?

@CodeZeno
Copy link

CodeZeno commented Dec 29, 2024

ChatGPT helped me fix this issue by updating utils.py

import os
import io
import sys
import torch
import base64
import numpy as np
import importlib
import subprocess
#import pkg_resources
#from pkg_resources import parse_version
import importlib.metadata as metadata
from packaging.version import parse as parse_version

from PIL import Image

from .logger import logger

class AnyType(str):
def ne(self, __value: object) -> bool:
return False

any_type = AnyType("*")

def ensure_package(package, version=None, install_package_name=None):
# Try to import the package
try:
module = importlib.import_module(package)
except ImportError:
logger.info(f"Package {package} is not installed. Installing now...")
install_command = _construct_pip_command(install_package_name or package, version)
subprocess.check_call(install_command)
else:
# If a specific version is required, check the version
if version:
try:
#installed_version = pkg_resources.get_distribution(package).version
installed_version = metadata.version(package)
if parse_version(installed_version) < parse_version(version):
logger.info(
f"Package {package} is outdated (installed: {installed_version}, required: {version}). Upgrading now..."
)
install_command = _construct_pip_command(install_package_name or package, version)
subprocess.check_call(install_command)
except metadata.PackageNotFoundError:
logger.info(f"Could not determine version for package {package}. Reinstalling...")
install_command = _construct_pip_command(install_package_name or package, version)
subprocess.check_call(install_command)

def _construct_pip_command(package_name, version=None):
if "python_embeded" in sys.executable or "python_embedded" in sys.executable:
pip_install = [sys.executable, "-s", "-m", "pip", "install"]
else:
pip_install = [sys.executable, "-m", "pip", "install"]

# Include the version in the package name if specified
if version:
    package_name = f"{package_name}=={version}"

return pip_install + [package_name]

def get_dict_attribute(dict_inst: dict, name_string: str, default=None):
nested_keys = name_string.split(".")
value = dict_inst

for key in nested_keys:
    # Handle array indexing
    if key.startswith("[") and key.endswith("]"):
        try:
            index = int(key[1:-1])
            if not isinstance(value, (list, tuple)) or index >= len(value):
                return default
            value = value[index]
        except (ValueError, TypeError):
            return default
    else:
        if not isinstance(value, dict):
            return default
        value = value.get(key, None)

    if value is None:
        return default

return value

def set_dict_attribute(dict_inst: dict, name_string: str, value):
"""
Set an attribute to a dictionary using dot notation.
If the attribute does not already exist, it will create a nested dictionary.

Parameters:
    - dict_inst: the dictionary instance to set the attribute
    - name_string: the attribute name in dot notation (ex: 'attributes[1].name')
    - value: the value to set for the attribute

Returns:
    None
"""
# Split the attribute names by dot
name_list = name_string.split(".")

# Traverse the dictionary and create a nested dictionary if necessary
current_dict = dict_inst
for name in name_list[:-1]:
    is_array = name.endswith("]")
    if is_array:
        open_bracket_index = name.index("[")
        idx = int(name[open_bracket_index + 1 : -1])
        name = name[:open_bracket_index]

    if name not in current_dict:
        current_dict[name] = [] if is_array else {}

    current_dict = current_dict[name]
    if is_array:
        while len(current_dict) <= idx:
            current_dict.append({})
        current_dict = current_dict[idx]

# Set the final attribute to its value
name = name_list[-1]
if name.endswith("]"):
    open_bracket_index = name.index("[")
    idx = int(name[open_bracket_index + 1 : -1])
    name = name[:open_bracket_index]

    if name not in current_dict:
        current_dict[name] = []

    while len(current_dict[name]) <= idx:
        current_dict[name].append(None)

    current_dict[name][idx] = value
else:
    current_dict[name] = value

def is_junction(src: str) -> bool:
import subprocess

child = subprocess.Popen('fsutil reparsepoint query "{}"'.format(src), stdout=subprocess.PIPE)
streamdata = child.communicate()[0]
rc = child.returncode
return rc == 0

def load_module(module_path, module_name=None):
import importlib.util

if module_name is None:
    module_name = os.path.basename(module_path)
    if os.path.isdir(module_path):
        module_path = os.path.join(module_path, "__init__.py")

module_spec = importlib.util.spec_from_file_location(module_name, module_path)

module = importlib.util.module_from_spec(module_spec)
module_spec.loader.exec_module(module)

return module

def pil2numpy(image: Image.Image):
return np.array(image).astype(np.float32) / 255.0

def numpy2pil(image: np.ndarray, mode=None):
return Image.fromarray(np.clip(255.0 * image, 0, 255).astype(np.uint8), mode)

def pil2tensor(image: Image.Image):
return torch.from_numpy(pil2numpy(image)).unsqueeze(0)

def tensor2pil(image: torch.Tensor, mode=None):
return numpy2pil(image.cpu().numpy().squeeze(), mode=mode)

def tensor2bytes(image: torch.Tensor) -> bytes:
return tensor2pil(image).tobytes()

def pil2base64(image: Image.Image):
buffered = io.BytesIO()
image.save(buffered, format="PNG")
img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
return img_str

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants