Skip to main content

comfy-env

Environment management and automatic CUDA wheel resolution/installation for ComfyUI custom nodes.

The Problem(s) and Solution(s)

Problem 1: ComfyUI custom nodes share a single Python environment. This breaks when:

  • Node A needs torch 2.4, Node B needs torch 2.8
  • Two packages bundle conflicting native libraries (libomp, CUDA runtimes, cv2)
  • A node requires a specific Python version (e.g., Blender needs 3.11, pymesh2 needs 3.9)

Solution 1: comfy-env provides process isolation -- nodes that need conflicting dependencies run in their own Python environments as persistent subprocesses, transparent to ComfyUI.

Two config files, two roles:

  • comfy-env-root.toml (root level): System packages (apt/brew) and ComfyUI node dependency management. Never touches the Python environment -- PyPI deps stay in requirements.txt.
  • comfy-env.toml (subdirectories): Each subdirectory with this file gets its own isolated Python environment via pixi, with a separate interpreter, conda packages, pip packages, and pre-built CUDA wheels.

Using conda CANNOT be avoided. We need to be able to use ComfyUI functions and return types within isolated nodes, which means they will need things like av or ffmpeg, and those cannot be installed through PyPI. Pixi is a convenient, fast, Rust-based package manager that speaks both conda-forge AND PyPI in the same pixi.toml, ships a real lockfile (so envs are reproducible across machines), installs entirely per-user with no admin / no system Python pollution, and uses uv under the hood for the PyPI side -- so it's as fast as the fastest thing in the ecosystem.

Problem 2: With the advent of ever more complex and useful Computer Vision ML models, code relies on CUDA packages like flash-attn, nvdiffrast, nunchaku, pytorch3d to work. Every single CUDA compiled wheel is compiled for:

  • Python ABI (3.10, 3.11, 3.12 etc)
  • Pytorch version when linking against pytorch, can be from 2.4 to 2.11
  • CUDA version (12.8, 13.0)
  • OS (Windows vs Linux)
  • GPU architectures (8.0 and above)

Solution 2: In order to ensure a smooth use and installation for ComfyUI users, we offer automatic wheel resolution through a cuda index: https://github.com/PozzettiAndrea/cuda-wheels.

Architecture

ComfyUI-MyPack/
+-- comfy-env-root.toml            # System packages + node deps
+-- install.py                     # from comfy_env import install; install()
+-- prestartup_script.py           # from comfy_env import setup_env; setup_env()
+-- __init__.py                    # from comfy_env import register_nodes
`-- nodes/
    +-- main/                      # No config -> imported in main process
    |   `-- __init__.py
    `-- cgal/                      # Has config -> isolated subprocess
        +-- comfy-env.toml
        `-- __init__.py

<workspace>/                       # %LOCALAPPDATA%\Programs\comfy-env  (Windows)
                                   # ~/.ce                              (Unix)
+-- pixi.toml                      # Generated from every discovered comfy-env.toml
`-- .pixi/envs/
    +-- mypack-cgal/               # Env for ComfyUI-MyPack/nodes/cgal/
    |   +-- python                 #   Complete Python interpreter
    |   `-- lib/.../site-packages/ #   + isolated packages
    `-- <plugin>-<subdir>/         # Each isolation config gets its own named env
        `-- ...

Env names are derived as <plugin>-<subdir> (or just <plugin> for root-level configs), with the ComfyUI- prefix stripped and the result lowercased: comfyui-sam3/nodes -> sam3-nodes, comfyui-motioncapture/nodes -> motioncapture-nodes, etc. See get_env_name.

Examples in the wild

  • ComfyUI-TRELLIS2 -- root-only config (comfy-env-root.toml). No isolation env; uses comfy-env purely for CUDA wheel resolution (flash-attn, sageattention) and to declare ComfyUI-GeometryPack as a node dependency. Runs inside the host ComfyUI process.
  • ComfyUI-Hunyuan3D-Part -- same pattern; lightest possible use of comfy-env.
  • ComfyUI-GeometryPack -- full isolation env. nodes/comfy-env.toml declares conda deps from conda-forge + a custom pozzettiandrea channel (CGAL, igl, bpy, pyvista), one CUDA package (cumesh), PyPI deps pinned via custom simple indexes (pyQuadriFlow, pygeogram, pypmp, pymesh2), and per-platform extras (mesalib/libglu/xorg-libsm on Linux, embreex/msvc-runtime on Windows). This is the env that doesn't fit in the host venv.
  • cookiecutter-comfy-extension -- scaffold for new node packs; ships a minimal comfy-env.toml template and the canonical install.py / prestartup_script.py / __init__.py triplet.

How It Works

Build time (install.py): For each subdirectory with a comfy-env.toml, comfy-env computes its env name (see above), generates a single pixi.toml in the workspace with one [environments.<name>] entry per discovered config, and runs pixi install -e <name> to materialize each environment. Identical env names from different ComfyUI installs share the same materialized env on disk -- env names act as the global identifier.

Workspace location: a single per-user pixi workspace, shared by every ComfyUI install on the machine. On Windows the default is %LOCALAPPDATA%\Programs\comfy-env (sits next to the ComfyUI Desktop install at %LOCALAPPDATA%\Programs\ComfyUI; never needs admin to create). If comfy-env detects an env at the legacy drive-root path C:\ce, it prints a one-line "please reinstall" nudge at startup so users notice the migration.

On Linux/MACOS the default is ~/.ce. Override with the COMFY_ENV_ROOT env var.

Runtime (register_nodes()): Discovers all node subdirectories. Those with a built env at <workspace>/.pixi/envs/<env_name>/ run in persistent subprocess workers using the isolated Python interpreter. Those without a config (or whose env hasn't been materialized yet) are imported normally in the main ComfyUI process. Workers communicate via Unix domain sockets (TCP on Windows) and support bidirectional callbacks for VRAM budget negotiation and progress reporting.

CUDA packages: Listed in [cuda], installed from the PyTorch wheel index or cuda-wheels -- pre-built wheels for nvdiffrast, pytorch3d, gsplat, flash-attn, etc. No CUDA toolkit or C++ compiler needed. The resolver tries the GitHub Pages simple index first, retries transient TCP-reset errors with a real User-Agent (corp proxies / AV products RST Python-urllib), and falls back to the GitHub Releases API on a different routing edge when Pages is unreachable end-to-end.

Startup logging

On every ComfyUI launch, comfy-env's prestartup hook tells you exactly where envs live and whether each one is built:

[comfy-env] Workspace: C:\Users\you\AppData\Local\Programs\comfy-env
[comfy-env] comfyui-motioncapture: 1 isolation env(s):
[comfy-env]   nodes -> C:\Users\you\...\custom_nodes\comfyui-motioncapture\nodes
[comfy-env]     env: C:\Users\you\AppData\Local\Programs\comfy-env\.pixi\envs\motioncapture-nodes  [OK]
[comfy-env] prestartup complete

[MISSING -- run install.py] instead of [OK] means the config was discovered but the pixi env hasn't been materialized; run the node's install.py to build it.

Usage

# install.py
from comfy_env import install
install()

# prestartup_script.py
from comfy_env import setup_env
setup_env()

# __init__.py
from comfy_env import register_nodes
NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS = register_nodes()
pip install comfy-env

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.4.6.tar.gz (120.7 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.4.6-py3-none-any.whl (138.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for comfy_env-0.4.6.tar.gz
Algorithm Hash digest
SHA256 24a8dd50ecdb64ef38b8a0050013ce235857803c6422e84a30c62918c3566b88
MD5 f4acf16a007d23bc13dd037c75e948be
BLAKE2b-256 fb91a84984114afecb898b9e6a9660844c70c0c71def90e1381cd692c2079f38

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_env-0.4.6.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.4.6-py3-none-any.whl.

File metadata

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

File hashes

Hashes for comfy_env-0.4.6-py3-none-any.whl
Algorithm Hash digest
SHA256 d81d4442f51e06f3ac1f04cb192470603aab2a3e783cbf64470f562d3eef1a30
MD5 b671032159facfacc616584a88848025
BLAKE2b-256 27cd27296ec4acac242069303fca3ff9dd87a334e0ff24abce3fa376b85cd1bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_env-0.4.6-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.

Release history Release notifications | RSS feed

Supported by

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