見出し画像

ComfyUIの通常インストール時の対応メモ(Windows)

※ Last update 08-13-2024
※ 参考用のメモです。必ずしも同様の問題が起こるとは限りません。




■ 0. 概要

▼ 0-0. 経緯等

 ポータブル版では無い方のComfyUIを久しぶりにインストールしたところ、そのままでは起動できませんでした。後学のため、問題の対応方法と、それを踏まえてのインストール方法を記載しておきます。

 なお、ポータブル版のインストールやFLUX.1を使用した画像の生成については、下記の記事に記載してあります。



■ 1. 対応を行った箇所

▼ 1-1. DLLの問題 (1/2)

 通常のインストール手順を済ませて起動しようとしたところ、下記のメッセージが出て実行が中断してしまいました。「fbgemm.dll」または依存関係のロードに失敗したという内容です。しかし、メッセージに書かれているパスのファイルは存在しています。

OSError: [WinError ***] The specified module could not be found. Error loading “***\ComfyUI\venv\Lib\site-packages\torch\lib\fbgemm.dll” or one of its dependencies.

 検索したところ、下記の投稿を見つけたので対応方法を確認しました。

Failed to import pytorch fbgemm.dll or one of its dependencies is missing - windows - PyTorch Forums
https://discuss.pytorch.org/t/failed-to-import-pytorch-fbgemm-dll-or-one-of-its-dependencies-is-missing/201969 

 ちなみに、下記をインストール(修復)する方法では解決しませんでした。既にインストールされています。

サポートされている最新の Visual C++ 再頒布可能パッケージのダウンロード
https://learn.microsoft.com/ja-jp/cpp/windows/latest-supported-vc-redist?view=msvc-170 

▼ 1-1. DLLの問題 (2/2)

 先ほどのフォーラムのコメントのを参考に、下記のツールを使用しました。これは、開発者がDLLの依存関係の問題を調べるために使うようです。

Dependencies (released this Oct 26, 2021)
https://github.com/lucasg/Dependencies/releases/tag/v1.11.1 

 DependenciesGui.exe を起動して、メッセージにあったパスの「fbgemm.dll」を開くと、足りないファイル「libomp140.x86_64.dll」が判明しました。

依存関係にある libomp140.x86_64.dll が見つからないことが判明

 配布場所(下記URL)を見つけたので、「libomp140.x86_64.dll」をダウンロードして、「fbgemm.dll」と同じ場所に設置したところ、無事に解決しました。念のため、システムディレクトリに設置するのはやめました。

libomp140.x86_64.dll - DLLme
※オフィシャルではないので自己責任でお願いします。
https://www.dllme.com/dll/files/libomp140_x86_64/00637fe34a6043031c9ae4c6cf0a891d 

▼ 1-3. Numpyのバージョン

 DLLの問題が解決してComfyUIは起動できましたが、毎回気になるメッセージが表示されます。「NumPy 1.x」でコンパイルされたモジュールを「NumPy 2.x」で実行するとクラッシュ(問題が発生)するかもよ、というニュアンスです。

A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.1 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.

If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.

Traceback (most recent call last): (略)

 おそらく問題はないと思いますが、NumPyのバージョンを下げます。

cd \aiwork\ComfyUI
venv\Scripts\activate
pip install "numpy<2"
deactivate

 これで起動したところ、気になるメッセージは表示されなくなりました。



■ 2. インストール手順

▼ 2-1. ダウンロード~環境構築

 1.を踏まえて、ComfyUIのインストール手順を記載します。Gitが必要です。「\aiwork\ComfyUI」をインストール先としますので、このディレクトリが存在しない状態から始めてください。異なるディレクトリへインストールする場合は、適宜読み替えてください。

 なお、細かい手順が変更される可能性がありますので(特にPyTorchのインストール部分)、なるべくリポジトリの「Manual Install」の項目を確認してください。

ComfyUIのリポジトリ
https://github.com/comfyanonymous/ComfyUI 

 それではコマンドプロンプトを起動して、下記のコマンドを順に実行します。

cd \aiwork
git clone https://github.com/comfyanonymous/ComfyUI

cd ComfyUI
python -m venv venv
venv\Scripts\activate

python -m pip install --upgrade pip

pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu121
pip install -r requirements.txt

pip install "numpy<2"

deactivate

 以上の手順が終わったら、1-2.の末尾にあるリンク先から「libomp140.x86_64.dll」をダウンロードして(ファイルの解凍が必要)、「\aiwork\ComfyUI\venv\Lib\site-packages\torch\lib」に移動します。

 起動用のバッチファイル「comfy.bat」を、「\aiwork」に設置します。インストールしたドライブ「C:」やディレクトリ「\aiwork\ComfyUI」は、適宜修正してください。

@echo off
C:
cd \aiwork\ComfyUI
call venv\Scripts\activate.bat
python main.py
call venv\Scripts\deactivate.bat
cd ..
pause

▼ 2-2. 起動の確認

 先ほどの「comfy.bat」を開き(エクスプローラー上からでも可)、正常に起動すると下記のようなメッセージが表示されます。Webブラウザで指示されたURLへアクセスして、UIが表示されることを確認します。

Starting server

To see the GUI go to: http://127.0.0.1:8188
ComfyUIの画面

 ここまでの手順ではモデルもワークフローも入れていないので、何もできません。適宜準備を行ってからComfyUIを起動し直してください。

▼ 2-3. ComfyUI Managerのインストール

 次に、ComfyUI Managerを導入します。これがあるとカスタムノードなどの管理が容易になります。

 まずはComfyUIを終了してください。次にコマンドプロンプト上で、下記のコマンドを順に実行します。

cd \aiwork\ComfyUI\custom_nodes
git clone https://github.com/ltdrdata/ComfyUI-Manager

 実行が完了したら、ComfyUIを起動します。メニューに「Manager」が増えているので、クリックすると開きます。

ComfyUI Managerを開いたところ

 ここでは便利な機能を一つだけ紹介します。入手したワークフローを読み込んだとき、必要なカスタムノードが導入されていないと下記のダイアログが表示され、ワークフローを使用することができません。

不足しているカスタムノードが表示された

 ダイアログを閉じてからManagerを開き、「Install Missing Custom Nodes」をクリックしてください。必要なカスタムノードを、この場でインストールすることが可能です。問題が無ければ、リスタートを行ってからWebブラウザをリロードするとすぐに使用できます。なお、インストールは1回では終わらない場合があります。

不足しているカスタムノードがインストールできる

 他にも様々な機能がありますが、まだ詳しくないので他の方に譲ります。



■ 3. おまけ

▼ 3-1. おまけ画像

 下記の記事に掲載した画面にある画像のプロンプトを、紹介し忘れていました。

 具体的には、下記のような画面です。

元記事の画面を再現したもの

 この画像のモデルは、下記のURLで配布している「flux1-dev-bnb-nf4.safetensors」です。NF4形式のFLUX.1モデルへの対応方法は、先ほどの記事に掲載してあります。プロンプトは自由にご利用ください。

https://huggingface.co/lllyasviel/flux1-dev-bnb-nf4 

A shy anime magical girl with long, flowing dark brown hair, wearing a frilly pink and white magical girl costume with ribbons and bows. Her cheeks are flushed, and her eyes are downcast as she leans in close to the viewer, a playful smile on her lips. She's holding a ornate magical wand with a heart-shaped gem. She's standing in a bustling amusement park, the colorful rides and crowds of people blurred in the background. The sun is setting, casting a warm golden glow over the scene. Soft, watercolor-style illustration with a dreamy, nostalgic atmosphere.

 もう一つ、表紙の画面に掲載された画像です。モデルは、下記のURLで配布している「flux1-salto-v1.1-bnb-nf4.safetensors」です。

https://huggingface.co/silveroxides/flux1-nf4-weights 

An extreme close-up of a shy anime girl's face from a high angle, captured with a fish-eye lens effect in her cozy bedroom. Her long, dark brown hair cascades around her flushed face as she sits on her bed, both arms outstretched towards the viewer in an inviting gesture. Her large, doe-like eyes gaze up with a mix of embarrassment and affection, while her lips form a soft, welcoming smile. The fish-eye effect warps the edges of the frame, revealing her summer sailor uniform and the pastel-colored bedding she's perched upon. In the warped background, glimpses of her room swirl into view: a desk with school books, cute posters on the walls, and a window letting in warm sunlight. The overall image has a whimsical, intimate feel, as if the viewer is being pulled into the girl's personal, enchanting world.



■ 4. その他

 私が書いた他の記事は、メニューよりたどってください。

 noteのアカウントはメインの@Mayu_Hiraizumiに紐付けていますが、記事に関することはサブアカウントの@riddi0908までお願いします。

いいなと思ったら応援しよう!