wsl ubuntu 安装stable-diffusion-webui

160 阅读2分钟

最近配了人生中第一台主机,上了个4070ti super显卡,玩3A游戏眩晕,只能拿这个卡跑跑大模型来玩玩了。先装个stable-diffusion玩玩

安装python

  1. 安装pyenv

ubuntu 24.04自带的版本是3.12,sd-webui要求是3.10或者3.11。使用pyenv安装管理python版本

➜  ~ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 24.04.1 LTS
Release:        24.04
Codename:       noble
➜  ~ python3 --version
Python 3.12.3
# 安装pyenv
curl https://pyenv.run | bash
# 安装 python 3.11.10
pyenv install 3.11.10
# 切换到3.11.10版本
pyenv global 3.11.10

curl [https://pyenv.run](https://pyenv.run) | bash安装不上可以修改一下自己的hosts,查一下域名对应的ip配置到hosts中

185.199.111.133 raw.githubusercontent.com

安装失败的话可能是缺少依赖

➜  ~ pyenv install 3.11.10
Downloading Python-3.11.10.tar.xz...
-> https://www.python.org/ftp/python/3.11.10/Python-3.11.10.tar.xz
Installing Python-3.11.10...

BUILD FAILED (Ubuntu 24.04 using python-build 20180424)

Inspect or clean up the working tree at /tmp/python-build.20250105203930.3197
Results logged to /tmp/python-build.20250105203930.3197.log

Last 10 log lines:
checking for pkg-config... no
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... "linux"
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/tmp/python-build.20250105203930.3197/Python-3.11.10':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details

安装相关依赖

  1. 基本开发工具和依赖
apt install -y build-essential libssl-dev zlib1g-dev libbz2-dev \
    libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
    xz-utils tk-dev libffi-dev liblzma-dev python3-dev python3-venv
  1. 安装gccapt install gcc
  2. 安装makeapt install make

安装cude

参考cuda官网

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.6.3/local_installers/cuda-repo-wsl-ubuntu-12-6-local_12.6.3-1_amd64.deb
sudo dpkg -i cuda-repo-wsl-ubuntu-12-6-local_12.6.3-1_amd64.deb
sudo cp /var/cuda-repo-wsl-ubuntu-12-6-local/cuda-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get -y install cuda-toolkit-12-6

安装完成后**<font style="color:rgb(44, 62, 80);">nvidia-smi</font>**查看安装效果

➜  download nvidia-smi
Sun Jan  5 21:13:30 2025
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 565.72                 Driver Version: 566.14         CUDA Version: 12.7     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GeForce RTX 4070 ...    On  |   00000000:01:00.0  On |                  N/A |
|  0%   36C    P0             46W /  295W |    1614MiB /  16376MiB |      1%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI        PID   Type   Process name                              GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|  No running processes found                                                             |
+-----------------------------------------------------------------------------------------+

安装sd-weiui

git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui
## 执行
webui.sh

不允许root启动,去webui.sh 修改一下代码 允许root启动 搜索root 自己改吧。

执行./webui.sh 报错

Cannot activate python venv, aborting…

#在stable-diffusion-webui目录下执行
python3 -c 'import venv'
python3 -m venv venv

Cannot locate TCMalloc (improves CPU memory usage)

sudo apt install libgoogle-perftools4 libtcmalloc-minimal4 -y