前言

最近终于有机会从围墙里往外看,了解到外面的世界已经有了天翻地覆的变化,感叹万千,笔者在本地mac,windows,linux,docker部署了不下20遍后,整理出来的linux极简避坑安装方案,供大家参考学习。

系统:linux

用户:py

python:3.10

涉及工具:wget、miniconda、git

Stable Diffusion WebUI简称:webui

安装目录:/data/

github地址

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

安装

miniconda

由于stable-diffusion-webui的安装需要特定的python版本,所以使用工具管理python库,且由于Anaconda过于臃肿,所以选择miniconda

# 安装wget工具,确保可以使用下载功能

yum install -y wget

# 安装miniconda

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

# 执行权限

chmod +x Miniconda3-latest-Linux-x86_64.sh

# 新建用户 py ## 由于webui默认不允许root用户执行,且新建用户更好的管理python

useradd py

# 新建目录

/data

# 将安装脚本移动到/data,方便管理

mv Miniconda3-latest-Linux-x86_64.sh /data/

#将data目录授权给py

chown -R py:py /data

# 安装miniconda

# 切换用户

su - py

cd /data

./Miniconda3-latest-Linux-x86_64.sh

##遇到输入写yes,其他按回车,安装完成

#安装完成后,默认没有(base)前缀,是环境还未生效,需要手动source

source /home/py/.bashrc

# 就会发现控制台由

[py@localhost ~]$

#变成了

(base) [py@localhost ~]$

# miniconda 安装完成

python 环境

# 使用conda 安装webui需要使用的环境

conda create --name sd python=3.10

# 使用sd环境,后续操作都在sd环境执行

conda activate sd

#控制台变为

(sd) [py@localhost ~]$

# 设置pip的阿里镜像源

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

pip config set install.trusted-host mirrors.aliyun.com

git

# 安装 git ,由于conda 可以安装工具,所以直接使用conda

conda install -y git

stable-diffusion-webui

# 下载github源码

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

# 启动

cd stable-diffusion-webui

./webui.sh

############该操作会执行较久的时间,来下载依赖,如遇到github依赖下载失败,多执行几遍,github网站在国内不算限制访问####

# 启动以后,如果程序没有发现已存在的模型,则会自动下载模型,该操作访问的是外网,所以需要手动下载模型,放到

# 模型所在的位置

/data/stable-diffusion-webui/models/Stable-diffusion/

# 这里上传了一个`dreamshaper_8`的模型,供大家在内网使用,见文章最后

# 内网启动会遇到如下报错,由于 https://huggingface.co/ 国内访问不了,所以有个依赖下载失败,该资源也提供下载,见文章最后

`OSError: Can't load tokenizer for 'openai/clip-vit-large-patch14'. If you were trying to load it from 'https://huggingface.co/models', make sure you don't have a local directory with the same name. Otherwise, make sure 'openai/clip-vit-large-patch14' is the correct path to a directory containing all relevant files for a CLIPTokenizer tokenizer.`

#下载该资源放到任意路径,本文放置/data/stable-diffusion-webui/下,/huggingface/transformers为资源内部目录

#调整报错的脚本

# /data/stable-diffusion-webui/repositories/stable-diffusion-stability-ai/ldm/modules/encoders/modules.py

openai/clip-vit-large-patch14

替换为

/data/stable-diffusion-webui/huggingface/transformers

################################

#最终启动

./webui.sh --skip-torch-cuda-test --no-half --use-cpu interrogate --listen --port 1111

#--skip-torch-cuda-test 没有显卡,跳过检查,不然起不来

#--no-half 降低精度,减少资源使用,不然起不来

#--use-cpu interrogate cpu的使用策略,可选 all

#--listen 该参数不加的话,只能本地访问,添加该参数,可以在其他客户端访问

#--port 指定端口,默认7860

web页面

默认是英文,本页面是安装了中文插件 https://github.com/VinsonLaro/stable-diffusion-webui-chinese.git

简单使用

输入提示词 1girl

模型下载地址:https://civitai.com/

dreamshaper_8模型下载|openai/clip-vit-large-patch14资源下载: 由于文件最大只能上传1000M,所以拆分成了多个文件: dreamshaper_8: Stable Diffusion WebUI -模型&依赖-001 Stable Diffusion WebUI -模型&依赖-002 Stable Diffusion WebUI -模型&依赖-003 huggingface|clip-vit-large-patch14: Stable Diffusion WebUI -模型&依赖-004 Stable Diffusion WebUI -模型&依赖-005 Stable Diffusion WebUI -模型&依赖-006 每个小块挂了1个积分,来抵消上传的流量费-_-,没有积分的同学可以私我

推荐阅读

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: