Windows11のWSL2 DebianでNVIDIA GPUを有効にしてStableDiffusionを動かす

2026-05-04 19:34:12

Windows11のWSL2 DebianでNVIDIA GPUを有効にしてStableDiffusionを動かす

Python3のライブラリがバージョンアップしたことでかみ合わせが悪くなってきました。2026年5月2日現在。

$ cat /etc/debian_version
12.11
$ python3 --version
Python 3.11.2

WS2 debian CUDA

Windows11のNVIDIAドライバーを入れてから、WSL2でNVIDIA GPUを設定する。

sudo apt-key del 7fa2af80
wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-wsl-ubuntu.pin
sudo mv cuda-wsl-ubuntu.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/12.0.0/local_installers/cuda-repo-wsl-ubuntu-12-0-local_12.0.0-1_amd64.deb
sudo dpkg -i cuda-repo-wsl-ubuntu-12-0-local_12.0.0-1_amd64.deb
sudo cp /var/cuda-repo-wsl-ubuntu-12-0-local/cuda-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get -y install cuda

WSL2 debian+StableDiffusion+ControlNet

install StableDiffusion

$ cd ~/src
$ git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git -b dev
$ cd stable-diffusion-webui

$ python3 -m venv .venv
$ . .venv/bin/activate

$ pip install insightface  controlnet_aux preprocessor scikit-image 'numpy<2,>=1.22.1' mediapipe==0.10.21

$ ./webui.sh

http://localhost:7861/

install ControlNet extension

$ cd ~\src
$ git clone https://github.com/Mikubill/sd-webui-controlnet.git
$ cd sd-webui-controlnet
$ cp models/ControlNet/control_v11p_sd15_canny.* ../stable-diffusion-webui/models/ControlNet

参考