Stable Diffusion WebUI 本地部署指南(Windows 11 + RTX 4060 Ti)

发布于:2025-06-11 ⋅ 阅读:(66) ⋅ 点赞:(0)

环境配置

  • 操作系统:Windows 11
  • 内存:32GB
  • GPU:NVIDIA RTX 4060 Ti (16GB)
  • Python 版本:3.10
  • CUDA 版本:12.1

一、准备工作

1. 安装必要工具

  • Git:用于克隆项目代码
  • Anaconda:用于创建和管理 Python 环境
  • NVIDIA 驱动:确保支持 CUDA 12.1+,建议安装最新版本

2. 创建 Python 环境

# 创建名为sdenv的Python 3.10环境
conda create -n sdenv python=3.10 -y

# 激活环境
conda activate sdenv

二、下载 WebUI 项目

方法 1:使用 Git 克隆(推荐)

# 克隆项目到当前目录
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git

# 进入项目目录
cd stable-diffusion-webui

方法 2:手动下载 Release 包

  1. 访问 Releases · AUTOMATIC1111/stable-diffusion-webui · GitHub
  2. 下载最新版本的 Source code (zip)
  3. 解压到任意目录,建议路径不含中文和特殊字符

三、安装依赖与配置环境

1. 设置 pip 镜像源(加速下载)

# 设置清华镜像为默认源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

# 添加阿里云镜像作为额外源
pip config set global.extra-index-url https://mirrors.aliyun.com/pypi/simple/

 手动下载cuda依赖:
    https://download.pytorch.org/whl/cu121/torch-2.1.2%2Bcu121-cp310-cp310-win_amd64.whl

进入虚拟环境后 pip install  cu121-cp310-cp310-win_amd64.whl 

pip install torch==2.1.2 torchvision==0.16.2 torchaudio==2.1.2

安装项目依赖

# 安装requirements.txt中的所有依赖
pip install -r requirements.txt

 

四、启动 WebUI

 

使用 Python 命令启动

bash

# 确保在虚拟环境中
python launch.py

五、访问 WebUI 界面

启动成功后,在浏览器中打开:

  • 本地访问:http://127.0.0.1:7860
  • 如需公网访问,添加--share参数启动:python launch.py --share

六、安装汉化包

方法:使用扩展安装

  1. 在 WebUI 中进入 Extensions 选项卡
  2. 点击 Install from URL
  3. 在输入框中填写:https://github.com/VinsonLaro/stable-diffusion-webui-chinese
  4. 点击 Install 按钮
  5. 安装完成后,在extensions-> install from url 里面填写 点击install之后 进入setting->user interface->User insterface, 勾选>
     Reload UI scripts when using Reload UI option 
    (useful for developing: if you make changes to UI scripts code, it is applied when the UI is reloded.)
    然后 Localization (requires restart)",选择 Chinese-All-0313 ,点击应用设置 再重启UI

下载模型:
stable-diffusion-v1-5
Hugging Face 访问不了可以去魔搭社区
直接下载  
 v1-5-pruned-emaonly.safetensors
 
存放目录如下:
stable-diffusion-webui/
├── models/
│   └── Stable-diffusion/
│       └── v1-5-pruned-emaonly.safetensors  # 模型文件
 

重启UI 就可以选中目标模型 

问题 分词器下载失败
处理: 虚拟环境下找到 \Lib\site-packages\huggingface_hub\constants.py 
修改国内镜像:
_HF_DEFAULT_ENDPOINT = "https://hf-mirror.com" 
 

最后附加成品效果