diff --git a/comfyui_to_python/node_runtime.py b/comfyui_to_python/node_runtime.py index d4782f8..e9127ff 100644 --- a/comfyui_to_python/node_runtime.py +++ b/comfyui_to_python/node_runtime.py @@ -258,8 +258,20 @@ def import_custom_nodes() -> None: "execution", os.path.join(comfyui_path, "execution.py") ) nodes_mod = _load_module("nodes", os.path.join(comfyui_path, "nodes.py")) + + # nodes.py inserts comfy/ subdirectory into sys.path, which shadows the + # top-level utils/ package (comfy/utils.py vs utils/). This breaks + # server.py → app.frontend_management → from utils.install_util import ... + # Filter it out temporarily so server.py loads cleanly. + comfy_subdir = os.path.join(comfyui_path, "comfy") + original_sys_path = list(sys.path) + sys.path[:] = [p for p in sys.path if p != comfy_subdir] + server_mod = _load_module("server", os.path.join(comfyui_path, "server.py")) + # Restore sys.path so nodes and other modules that need comfy/ still work + sys.path[:] = original_sys_path + if execution_mod is None or server_mod is None: log.debug( "import_custom_nodes: could not load execution/server modules. " diff --git a/tests/runtime/generated/upscale-model-loader.py b/tests/runtime/generated/upscale-model-loader.py index 6e04ee5..642d7aa 100644 --- a/tests/runtime/generated/upscale-model-loader.py +++ b/tests/runtime/generated/upscale-model-loader.py @@ -268,8 +268,20 @@ def import_custom_nodes() -> None: "execution", os.path.join(comfyui_path, "execution.py") ) nodes_mod = _load_module("nodes", os.path.join(comfyui_path, "nodes.py")) + + # nodes.py inserts comfy/ subdirectory into sys.path, which shadows the + # top-level utils/ package (comfy/utils.py vs utils/). This breaks + # server.py → app.frontend_management → from utils.install_util import ... + # Filter it out temporarily so server.py loads cleanly. + comfy_subdir = os.path.join(comfyui_path, "comfy") + original_sys_path = list(sys.path) + sys.path[:] = [p for p in sys.path if p != comfy_subdir] + server_mod = _load_module("server", os.path.join(comfyui_path, "server.py")) + # Restore sys.path so nodes and other modules that need comfy/ still work + sys.path[:] = original_sys_path + if execution_mod is None or server_mod is None: log.debug( "import_custom_nodes: could not load execution/server modules. "