Skip to main content

Environment management for ComfyUI custom nodes - CUDA wheel resolution and process isolation

Project description

comfy-env

Environment management for ComfyUI custom nodes.

Quick Start

pip install comfy-env

1. Create comfy-env-root.toml in your node directory:

[cuda]
packages = ["nvdiffrast", "pytorch3d"]

[apt]
packages = ["libgl1-mesa-glx"]

[node_reqs]
ComfyUI_essentials = "cubiq/ComfyUI_essentials"

PyPI deps go in requirements.txt (standard ComfyUI pattern).

2. In install.py:

from comfy_env import install
install()

3. In prestartup_script.py:

from comfy_env import setup_env
setup_env()

Two Config Files

File Purpose
comfy-env-root.toml Main node config (root level)
comfy-env.toml Isolated subfolder config

comfy-env-root.toml (main node)

[cuda]
packages = ["nvdiffrast", "pytorch3d"]

[apt]
packages = ["libgl1-mesa-glx"]

[dependencies]
cgal = "*"

[env_vars]
KMP_DUPLICATE_LIB_OK = "TRUE"

[node_reqs]
ComfyUI_essentials = "cubiq/ComfyUI_essentials"

PyPI deps -> requirements.txt

comfy-env.toml (isolated folder)

python = "3.11"

[dependencies]
cgal = "*"

[pypi-dependencies]
trimesh = { version = "*", extras = ["easy"] }

[env_vars]
SOME_VAR = "value"

What goes where?

Section Root Isolated
[cuda] [x] [x]
[apt] [x] [x]
[dependencies] [x] [x]
[env_vars] [x] [x]
[node_reqs] [x] [ ]
python = "X.Y" [ ] [x]
[pypi-dependencies] [ ] [x]

Process Isolation

For nodes with conflicting dependencies:

# In nodes/__init__.py
from pathlib import Path
from comfy_env import wrap_isolated_nodes

from .cgal import NODE_CLASS_MAPPINGS as cgal_mappings

NODE_CLASS_MAPPINGS = wrap_isolated_nodes(
    cgal_mappings,
    Path(__file__).parent / "cgal"  # Has comfy-env.toml
)

Each wrapped node runs in a subprocess with its own Python environment.


CLI

comfy-env init              # Create comfy-env-root.toml
comfy-env init --isolated   # Create comfy-env.toml (for subfolders)
comfy-env install           # Install dependencies
comfy-env install --dry-run # Preview
comfy-env info              # Show runtime info
comfy-env doctor            # Verify packages
comfy-env apt-install       # Install system packages

API

install()

from comfy_env import install
install()

setup_env()

from comfy_env import setup_env
setup_env()  # Call in prestartup_script.py

wrap_isolated_nodes()

from comfy_env import wrap_isolated_nodes
wrapped = wrap_isolated_nodes(NODE_CLASS_MAPPINGS, node_dir)

Detection

from comfy_env import RuntimeEnv, detect_cuda_version, detect_gpu

env = RuntimeEnv.detect()
print(env)  # Python 3.11, CUDA 12.8, PyTorch 2.8.0, GPU: RTX 4090

Example

See ComfyUI-GeometryPack:

  • Multiple isolated environments (CGAL, Blender, GPU)
  • Per-subdirectory comfy-env.toml
  • Different Python versions

Why?

Why isolation? ComfyUI nodes share one Python. Conflicts happen when:

  • Node A needs torch 2.4, Node B needs torch 2.8
  • Two packages bundle incompatible libomp
  • Blender API requires Python 3.11

Why CUDA wheels? Installing nvdiffrast normally needs CUDA toolkit + C++ compiler + 30 min compilation. cuda-wheels provides pre-built wheels.

How envs work:

  • Central cache: ~/.comfy-env/envs/
  • Marker files link nodes -> cached envs
  • Config hash in name -> changes create new envs

License

MIT

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

comfy_env-0.1.73.tar.gz (54.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

comfy_env-0.1.73-py3-none-any.whl (66.7 kB view details)

Uploaded Python 3

File details

Details for the file comfy_env-0.1.73.tar.gz.

File metadata

  • Download URL: comfy_env-0.1.73.tar.gz
  • Upload date:
  • Size: 54.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for comfy_env-0.1.73.tar.gz
Algorithm Hash digest
SHA256 9cfd43f7916b9cda2739315658636bae22ea105274fb8caf355ac6dc24bba8e3
MD5 db579fccd48ce94feda34e5ca425117d
BLAKE2b-256 8c4f0f1cfa78766dcf37b604b21e6199f01d5ac6c5c51e215aa3c5675c43fb3b

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_env-0.1.73.tar.gz:

Publisher: publish.yml on PozzettiAndrea/comfy-env

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file comfy_env-0.1.73-py3-none-any.whl.

File metadata

  • Download URL: comfy_env-0.1.73-py3-none-any.whl
  • Upload date:
  • Size: 66.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for comfy_env-0.1.73-py3-none-any.whl
Algorithm Hash digest
SHA256 de7ef222d7e6572d537f67bab4cf4e18a9e04cf38c1fd930223a0c40536f25a5
MD5 07d8238a2a59f9629de150d158fc4ff4
BLAKE2b-256 6d0ffe8d16ca950529b5952ae8d6a0cee23eb04c878f9fbf38731533c95a56ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_env-0.1.73-py3-none-any.whl:

Publisher: publish.yml on PozzettiAndrea/comfy-env

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page