このブログでは、YouTube内で紹介したコマンドを紹介します。この記事と一緒にYouTube動画をご覧ください。動画では、ComfyUIをVENV仮想環境に構築する方法を、解説しています。仮想環境にComfyUIをセットアップすることで、ComfyUIを組み込んだアプリの開発がしやすくなったり、ライブラリを管理しやすくなるメリットがあります。是非、動画を見て、VENV仮想環境にComfyUIをセットアップする方法を学びましょう。
1. Pythonのインストール
今回のセットアップでは、Python3.12を使います。導入していない方は、下のリンクの公式ページからダウンロードしてインストールしましょう。
2. 仮想環境のセットアップ
ストレージ直下にフォルダを作って、そのフォルダをPowerShellやコマンドプロンプトで開きます。下記のコマンドを入力してVENV仮想環境を作ります。その中に、ComfyUIをセットアップします。
py -3.12 -m venv venv
venv\Scripts\activate
python -m pip install -U pip setuptools
pip install comfy-cli
comfy --here install
python ComfyUI\main.py --listen 127.0.0.1 --port 8188
もし、「venv\Scripts\activate」でエラーが起こる場合は、PowerShellを管理者権限で立ち上げて、下記のコマンドを入力します。
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
もし、「comfy –here install」でcudaのバージョンエラーが出る場合は、代わりに下記のコマンドを入力します。
comfy --here install --cuda-version 12.6
ComfyUIをセットアップできたら、ブラウザに下記のアドレスを入力して、ComfyUIを開きます。
3. ComfyUIの起動用バッチファイルの作成
メモ帳などのテキストファイルで、作成して、「run_comfyui.bat」などの拡張子「bat」のバッチファイルを作りましょう!作成したバッチファイルは「2」で作成したフォルダの下に配置します。
@echo off
pushd %~dp0
call ".\venv\Scripts\activate.bat"
python ComfyUI\main.py --windows-standalone-build
pause
4.モデルのダウンロード
画像生成モデルとVAEモデルをダウンロードします。ここでは、アニメ系画像の生成が得意なanimegineXL4.0を使います。

上の2つのリンク先から、「animagineXL_40_v40pt.safetensors」と「sdxl_vae.safetensors」をダウンロードします。ダウロードした2つのファイルは、下記の保存場所に保存します。

5. 画像生成のテスト
ComfyUIで画像生成のテストをします。生成条件は下記の通りです。
モデル:animagineXL40_v4Opt
VAE:sdxl_vae
サンプラー:Euler ancestral
ステップ数:30
CFGスケール:4.0
サイズ:896 x 1216 (W H)
ポジティブプロンプト:
masterpiece, best quality, ultra‐detailed, 1girl, solo, young elf, pointed ears, long flowing silver hair, luminous emerald eyes, standing in an enchanted forest, shafts of golden light filtering through ancient trees, soft glowing particles in the air, lush mossy roots and foliage, magical atmosphere, fantasy, cinematic volumetric lighting, backlight, intricate highlights on hair and eyes, captivating expression, delicate facial features, anime style illustration, focus on face and eyes, dynamic composition, high resolution
ネガティブプロンプト:
lowres, bad quality, blurry, deformed, disfigured, extra limbs, extra fingers, multiple heads, bad hands, poorly drawn face, watermark, signature, text, jpeg artifacts

コメント