ComfyUI-to-Python-Extension icon indicating copy to clipboard operation
ComfyUI-to-Python-Extension copied to clipboard

ModuleNotFoundError: No module named 'utils.json_util'; 'utils' is not a package

Open bozagina opened this issue 10 months ago • 11 comments

I've added these lines of code in comfyui_to_python.py: Image but now: (env) (base) PS D:\pinokio\api\comfy.git\app\custom_nodes\ComfyUI-to-Python-Extension> python comfyui_to_python.py current_dir:D:\pinokio\api\comfy.git\app\custom_nodes\ComfyUI-to-Python-Extension Traceback (most recent call last): File "D:\pinokio\api\comfy.git\app\custom_nodes\ComfyUI-to-Python-Extension\comfyui_to_python.py", line 649, in main() File "D:\pinokio\api\comfy.git\app\custom_nodes\ComfyUI-to-Python-Extension\comfyui_to_python.py", line 643, in main run(**vars(pargs)) File "D:\pinokio\api\comfy.git\app\custom_nodes\ComfyUI-to-Python-Extension\comfyui_to_python.py", line 608, in run ComfyUItoPython( File "D:\pinokio\api\comfy.git\app\custom_nodes\ComfyUI-to-Python-Extension\comfyui_to_python.py", line 552, in init self.execute() File "D:\pinokio\api\comfy.git\app\custom_nodes\ComfyUI-to-Python-Extension\comfyui_to_python.py", line 562, in execute import_custom_nodes() File "D:\pinokio\api\comfy.git\app\custom_nodes\ComfyUI-to-Python-Extension\comfyui_to_python_utils.py", line 15, in import_custom_nodes import server File "D:\pinokio\api\comfy.git\app\server.py", line 34, in from app.custom_node_manager import CustomNodeManager File "D:\pinokio\api\comfy.git\app\app\custom_node_manager.py", line 18, in from utils.json_util import merge_json_recursive ModuleNotFoundError: No module named 'utils.json_util'; 'utils' is not a package

bozagina avatar Feb 09 '25 14:02 bozagina

Image

bozagina avatar Feb 09 '25 14:02 bozagina

Same for me, unfortunately, it seems to be a comfyUI itself issue.

EvelinaAleksiutenko avatar Feb 13 '25 14:02 EvelinaAleksiutenko

I have the same problem, is there any solution?

babyta avatar Feb 14 '25 10:02 babyta

Module Import Issue: ModuleNotFoundError: No module named 'utils.json_util'

Issue Summary

We encountered an issue where utils.json_util is not recognized as a module when running:

PYTHONPATH=/workspace/ComfyUI python3 -m custom_nodes.ComfyUI-to-Python-Extension.comfyui_to_python -f relighting_v6.json

Despite utils/ existing inside /workspace/ComfyUI/, Python fails to import it:

ModuleNotFoundError: No module named 'utils.json_util'; 'utils' is not a package

Adding debug logs shows /workspace/ComfyUI is in sys.path, and import utils.json_util works inside a Python shell, but the script still fails.


Steps Taken to Debug

  1. Verified that /workspace/ComfyUI/utils/json_util.py exists and has an __init__.py.
  2. Confirmed the import works manually in a Python shell:
    import utils.json_util
    print(utils.json_util)
    
  3. Checked sys.path before failure and ensured /workspace/ComfyUI was included.
  4. Manually forced /workspace/ComfyUI at the top of sys.path inside comfyui_to_python.py:
    import sys
    sys.path.insert(0, "/workspace/ComfyUI")
    
  5. Removed /workspace/ComfyUI/comfy from sys.path, as it was interfering with imports.
  6. Cleared all __pycache__ and .pyc files and restarted the environment:
    find /workspace/ComfyUI -name "__pycache__" -type d -exec rm -r {} +
    find /workspace/ComfyUI -name "*.pyc" -delete
    

Current Behavior

  • Python still throws:
    ModuleNotFoundError: No module named 'utils.json_util'; 'utils' is not a package
    
    when running the script.
  • However, import utils.json_util works in an interactive Python shell.

webel avatar Feb 14 '25 13:02 webel

这是来自QQ邮箱的假期自动回复邮件。您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。

babyta avatar Feb 14 '25 13:02 babyta

Try rename the folder 'utils' in ComfyUI folder to another one, e.g. 'utilities'.

'utils' may conflicts with utils.py in the comfyui folder.

Do remember do the ‘rename refactoring’, make sure references are renamed too.

zhouyi531 avatar Feb 15 '25 03:02 zhouyi531

Try rename the folder 'utils' in ComfyUI folder to another one, e.g. 'utilities'.

'utils' may conflicts with utils.py in the comfyui folder.

Do remember do the ‘rename refactoring’, make sure references are renamed too. Good method, the test can pass, thank you

babyta avatar Feb 17 '25 05:02 babyta

that probably works given I've stumbled on the same issue earlier with restricted naming being used for directories, I ended up just copying over what I needed from utils.

webel avatar Feb 27 '25 21:02 webel

Same issue here. And I suppose that the sys.path.insert(0, ... in nodes.py may cause a ambiguity between utils/ and comfy/utils.py

ianmage avatar Mar 08 '25 14:03 ianmage

a simple alternative way: add the only function merge_json_recursive from ComfyUI/utils/json_util.py to ComfyUI/app/custom_node_manager.py, and comment out the import line from utils.json_util import merge_json_recursive

colehank avatar Mar 12 '25 09:03 colehank

It is recommended to use portable comfyui instead of desktop version, and then use my pr version, https://github.com/pydn/ComfyUI-to-Python-Extension/pull/133

xiaoxidashen avatar Sep 07 '25 06:09 xiaoxidashen