🖼️

windows11で stable-diffusion-webui の環境構築

2023/01/06に公開

事前準備

1. Python3.10.6をインストール

一番シンプルなインストール方法

https://www.python.org/downloads/release/python-3106/ の「Files」の 「Windows installer (64-bit)」をダウンロードしてインストールする

pythonの複数バージョンを切り替えたい場合

自分はpythonの複数バージョンを切り替えたいのでpyenvをinstallしました

  1. git clone https://github.com/pyenv-win/pyenv-win.git "~/.pyenv"

  2. Pathに .pyenv\pyenv-win\bin への絶対パスを追加
    PYENVPYENV_HOME にも同じパスを追加
    Pathに.pyenv\pyenv-win\shimsへの絶対パスを追加(後でpython install時に作成されるディレクトリ)

  3. この時、環境変数を %USERPROFILE%\AppData\Local\Microsoft\WindowsApps より上に定義しないとpython と打った時にWondows Appsが開いてしまうので注意

  4. PowerShellを再起動して pyenv install 3.10.6, pyenv global 3.10.6

  5. python --version すると 3.10.6 と表示される

2. Gitをインストール

git windows install で調べてください
例: https://www.curict.com/item/60/60bfe0e.html

3. windows11にdockerをinstallする

https://zenn.dev/kkj/articles/ca83f4b5d13e68
https://techracho.bpsinc.jp/mataka345/2021_12_13/114058

4. docker コンテナからGPUを使えるようにする

この記事を参考にしました
https://qiita.com/kekekekenta/items/d0d64688c889b860beba

  1. CUDAをインストール
  2. 参考記事のdockerコマンドを一通り実行して動作することを確認する ←必須じゃない
  3. dockerを再起動する
    4. restart-service *docker*

Docker上で実行する

参考: https://zenn.dev/karaage0703/articles/bf86fe4946417b

  1. stable-diffusion-webui-dockerのgitリポジトリをpullしてくる
    • git clone git@github.com:AbdBarho/stable-diffusion-webui-docker.git
  2. cloneしてきたディレクトリに入って docker compose --profile auto up --build
    • docker imageを再ビルドして /docker-sompose.yml に記述されているauto が実行される
  3. デフォルトはポート7860で立ち上がる
    • localhost:7860

トラブルシューティング

  1. docker compose download upだとweb serverが立ち上がらないので注意
    ダウンロードだけやって落ちる
    https://github.com/AbdBarho/stable-diffusion-webui-docker/issues/353
webui-docker-download-1  | By using this software, you agree to the following licenses:
webui-docker-download-1  | https://github.com/AbdBarho/stable-diffusion-webui-docker/blob/master/LICENSE
webui-docker-download-1  | https://github.com/CompVis/stable-diffusion/blob/main/LICENSE
webui-docker-download-1  | https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/master/LICENSE.txt
webui-docker-download-1  | https://github.com/invoke-ai/InvokeAI/blob/main/LICENSE
webui-docker-download-1  | https://github.com/sd-webui/stable-diffusion-webui/blob/master/LICENSE
webui-docker-download-1  | https://github.com/cszn/BSRGAN/blob/main/LICENSE
webui-docker-download-1  | https://github.com/sczhou/CodeFormer/blob/master/LICENSE
webui-docker-download-1  | https://github.com/TencentARC/GFPGAN/blob/master/LICENSE
webui-docker-download-1  | https://github.com/xinntao/Real-ESRGAN/blob/master/LICENSE
webui-docker-download-1  | https://github.com/xinntao/ESRGAN/blob/master/LICENSE
webui-docker-download-1  | https://github.com/cszn/SCUNet/blob/main/LICENSE
webui-docker-download-1 exited with code 0

Discussion