0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ComfyUIのカスタムノード開発環境を構築する手順

Posted at

環境

  • Windows
  • Python 3.12

2025年5月現在、ComfyUIのGitHubの Manual Install の項目には、Pythonの推奨のバージョンは3.12となっています。

開発環境の構築

公式ドキュメント に従い、ComfyUIcomfy-cli をインストールします。開発環境で使用するComfyUIについては、ドキュメントで手動インストールを勧めているのでそちらの手順を記載します。

仮想環境の構築

uv でプロジェクトと仮想環境を作成し、アクティベートします。

PowerShell
uv init --bare --python 3.12
uv venv --python 3.12
.venv\Scripts\activate.ps1

コマンドプロンプトでアクティベートする場合は ps1 ファイルではなく bat ファイルを実行してください。

CMD
.venv\Scripts\activate.bat

ComfyUIのclone

プロジェクトの直下にComfyUIのリポジトリをCloneします。

git clone https://github.com/comfyanonymous/ComfyUI.git

PyTorchのインストール

CUDAの依存関係を設定するために、以下の内容を pyproject.toml に追記します。

[tool.uv.sources]
torch = { index = "pytorch-cu126" }
torchvision = { index = "pytorch-cu126" }

[[tool.uv.index]]
name = "pytorch-cu126"
url = "https://download.pytorch.org/whl/cu126"
explicit = true

追記後、下記のコマンドで PyTorch をインストールします。

uv add torch torchvision torchaudio

ComfyUIの依存ライブラリのインストール

ComfyUIの依存ライブラリを ComfyUI\requirements.txt からインストールします。

cd ComfyUI
pip install -r requirements.txt

また参考としてuvを使用して ComfyUI\requirements.txt の内容を pyproject.toml に追記しながらインストールする方法を紹介します。

PowerShell
Get-Content ComfyUI\requirements.txt | Where-Object {$_ -notmatch "^#|^$"} | ForEach-Object { uv add $_ }

コマンドプロンプトの場合は下記のコマンドとなります。

CMD
for /f "tokens=1 delims=#" %i in ('findstr /v "^#" ComfyUI\requirements.txt ^| findstr /v "^$"') do uv add %i

uv add を実行する場合、requirements.txt のコメントと空行をスキップする必要があるため、判定の処理を入れています。

コマンドラインツールのインストール

uv add comfy-cli

コマンドラインツールのインストールまで完了すると、下記のコマンドでComfyUIが起動できるようになります。

comfy launch

カスタムノードについて

配置場所とサンプル

カスタムノードは ComfyUI/custom_nodes ディレクトリに配置することで使用できるようになります。また、このディレクトリにはサンプルとして example_node.py.example というファイルが同梱されており、example_node.py にリネームすると Example Node として確認することができます。

開発用ディレクトリの作成

コマンドラインツールに node scaffold というコマンドがあり、こちらを使用すると開発用の初期ディレクトリを作成できます。

cd ComfyUI\custom_nodes
comfy node scaffold

単一ファイルでもカスタムノードとして利用できますが、カスタムノードの公開を考えている場合は、上記のコマンドで初期ディレクトリを作成すると便利です。

ノードの公開方法の詳細は公式ドキュメントにまとめられています。
Registry | Overview

その他

公式ドキュメント以外では、標準で同梱されているノードのソースコードも、実装の参考になります。ComfyUI/nodes.py を見ると実装がわかるので、こちらと公式ドキュメントを照らし合わせながら作成を始めると良いかと思います。

参考

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?