pydn / ComfyUI-to-Python-Extension

A powerful tool that translates ComfyUI workflows into executable Python code.
MIT License
842 stars 87 forks source link

Run with ComfyUI's python_embeded #15

Closed nistvan86 closed 10 months ago

nistvan86 commented 10 months ago

When following your instructions, the requirements of this extension gets installed to the system's Python site-packages directory. This don't works for me as the installed torch there has no CUDA acceleration and the script fails.

e:\aistuff\ComfyUI_windows_portable\ComfyUI\ComfyUI-to-Python-Extension>python comfyui_to_python.py
Traceback (most recent call last):
  File "e:\aistuff\ComfyUI_windows_portable\ComfyUI\ComfyUI-to-Python-Extension\comfyui_to_python.py", line 17, in <module>
    from nodes import NODE_CLASS_MAPPINGS
  File "e:\aistuff\ComfyUI_windows_portable\ComfyUI\ComfyUI-to-Python-Extension\..\nodes.py", line 20, in <module>
    import comfy.diffusers_load
  File "e:\aistuff\ComfyUI_windows_portable\ComfyUI\ComfyUI-to-Python-Extension\..\comfy\diffusers_load.py", line 4, in <module>
    import comfy.sd
  File "e:\aistuff\ComfyUI_windows_portable\ComfyUI\ComfyUI-to-Python-Extension\..\comfy\sd.py", line 5, in <module>
    from comfy import model_management
  File "e:\aistuff\ComfyUI_windows_portable\ComfyUI\ComfyUI-to-Python-Extension\..\comfy\model_management.py", line 108, in <module>
    total_vram = get_total_memory(get_torch_device()) / (1024 * 1024)
  File "e:\aistuff\ComfyUI_windows_portable\ComfyUI\ComfyUI-to-Python-Extension\..\comfy\model_management.py", line 76, in get_torch_device
    return torch.device(torch.cuda.current_device())
  File "C:\Python\lib\site-packages\torch\cuda\__init__.py", line 674, in current_device
    _lazy_init()
  File "C:\Python\lib\site-packages\torch\cuda\__init__.py", line 239, in _lazy_init
    raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled

I think a better way would be installing/running it with the ComfyUI python_embeded. I've tried installing requirements there:

e:\aistuff\ComfyUI_windows_portable\ComfyUI\ComfyUI-to-Python-Extension>..\..\python_embeded\python.exe -s -m pip install -r requirements.txt

But then execution doesn't seem to find the utils module next to the script.

e:\aistuff\ComfyUI_windows_portable\ComfyUI\ComfyUI-to-Python-Extension>..\..\python_embeded\python.exe -s comfyui_to_python.py
Traceback (most recent call last):
  File "e:\aistuff\ComfyUI_windows_portable\ComfyUI\ComfyUI-to-Python-Extension\comfyui_to_python.py", line 14, in <module>
    from utils import import_custom_nodes, find_path, add_comfyui_directory_to_sys_path, add_extra_model_paths, get_value_at_index
ModuleNotFoundError: No module named 'utils'
pydn commented 10 months ago

I'd recommend using a venv or conda environment when installing dependencies. For cuda acceleration just follow the getting started instructions on the pytorch website. Then pip install requirements for the extension. Also, the script assumes you navigate to the same directory as the comfyui_to_python script in your terminal because it expects utils.py to be in the current working directory.

nistvan86 commented 10 months ago

Thanks! I assumed the installation of requirements.txt of this repo is enough to make it working. Installing pytorch manually with CUDA in a venv made it go further.

It's worth noting that custom_node requirements also need to be manually installed when going with the custom venv route.

It also seems the ComfyUI_NestedNodeBuilder extension is not compatible with this script, as it cannot load my nested node definitions. But that's something I'm thinking about dropping if this script-ability thing works out for me.