Home

Published

- 3 min read

stable diffusion 本地安装

img of stable diffusion 本地安装

安装conda环境

在安装之前,需要先下载并安装 miniconda miniconda 是一个轻量级的 conda 发行版,可以快速地安装和管理 conda 环境。

下载地址:https://docs.conda.io/en/latest/miniconda.html

比如: windows 安装完成后,打开命令行窗口,输入以下命令创建一个名为 sd_3106 python 3.10.6 环境:

    conda create -p D:\ProgramData\miniconda3\envs\sd_3106 python=3.10.6  

2.克隆代码

打开命令行窗口,输入以下命令克隆代码: 当然如果你本地没有 Git 环境,那么请先下载安装Git:https://git-scm.com/download/win

    git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui  

3.设置 pip 镜像源

由于国内访问 pypi 可能会比较慢,我们可以设置 pip 镜像源来加速下载。

输入以下命令设置 pip 镜像源为阿里云:

    pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
  

4.升级pip

输入以下命令升级pip:

    D:\ProgramData\miniconda3\envs\sd_3106\Scripts\python.exe -m pip install --upgrade pip
  

5.GPU环境检查

Stable Diffusion 推荐的 GPU 运行环境为 NVIDIA GPU ,当然 AMD GPU 也是可以的但是不推荐(AMD GPU安装

    wmic path win32_VideoController get name
  

如果输出带有 : AMD Radeon 则表示你的显卡为 AMD 架构,这时请按照上面连接安装,如果输出 NVIDIA GeForce 关键词,则表示你的显卡为 NVIDIA GPU,此时你需要下载另一个叫做 CUDA(CUDA 是 NVIDIA 公司推出的一种通用并行计算架构) 的东西。

6.下载Cuda

NVIDIA 的 GPU 架构和 cuda 有对应关系,可以在网上查找对应关系。

cuda 下载地址:https://developer.nvidia.com/cuda-downloads

7.运行webui

输入以下命令启动 stable diffusion webui

因为中间下载的东西很多都是从Github下载,所以国内下载速度很慢,此时需要你自己去科学上网

    # windows
webui-user.bat
# linux 
webui-user.sh  

8.报错指南

如果在运行脚本时遇到报错,大概率是网络问题导致的下载失败 打开 stable-diffusion-webui/launch.py 然后找到 prepare_environment() ,可以看到好几个 https://github.com 的链接,在其前添加: https://ghproxy.com/

添加后类似: https://ghproxy.com/https://github.com/.... . 然后保存继续执行脚本即可。