最详细的Ubuntu服务器搭建Stable-Diffusion教程(无显卡,仅用CPU)

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

1. 首先安装基本工具

# 安装python环境
sudo apt install wget git

若已经安装过请忽略

2. 安装miniconda也可以自己下载python

下载最新的安装包

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

执行安装

./Miniconda3-latest-Linux-x86_64.sh

一路回车遇到选择就yes切记要yes不然要手动添加环境变量
刷新环境

source .bashrc

此时命令行输入python看到是3.10版本的就对了

(base) root@localhost:~# python
Python 3.10.9 (main, Jan 11 2023, 15:21:40) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

后续步骤可以用conda新建一个虚拟环境进行我的服务器是临时的所以就直接在base环境下进行了

3. git拉取项目到本地

执行

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

进入项目目录下

cd stable-diffusion-webui/

4. 安装对应Python依赖包

首先安装pytorchtorchvision若是GPU环境的用户需要安装与cuda版本对应的torchcpu环境则无具体要求

pip install torch==1.13.1+cu117 torchvision==0.14.1+cu117 --extra-index-url https://download.pytorch.org/whl/cu116

然后给pip换上中科大的源也可以换清华源或阿里源

pip config set global.index-url https://mirrors.ustc.edu.cn/pypi/web/simple

接着安装对应依赖

pip install -r requirements_versions.txt

5. 从huggingface下载预训练模型参数

进入模型存放对应目录

cd models/Stable-diffusion/

下载一个模型这里可以根据自己的需要下载

wget https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/resolve/main/sd-v1-4-full-ema.ckpt

6. 启动项目

到这一步网上很多方法都是直接执行根目录下的webui.sh我执行时有报错就换了一种方式

回到项目根目录执行launch.py文件启动web服务并指定监听端口为1234端口号随意

python3 launch.py --port 1234 --listen

若为cpu环境则需提前执行

export COMMANDLINE_ARGS=--skip-torch-cuda-test

并且在运行时加入no-half

python3 launch.py --no-half --port 1234 --listen

启动后安装很多依赖以及克隆相应github仓库过程有报错的可以看附录解决方案并重新执行这一步
若出现以下内容则说明启动成功

此时访问http://127.0.0.1:1234即可使用

7. 公网访问

若想让服务能在公网上被其他用户访问则需进入weibu.py文件修改对应代码将shared.demo.launch()第一行参数改为share=True。

然后重新启动项目此时能看到公网地址说明成功

访问以上临时的公网地址就可以让别人也使用你的AI作图了

8. 汉化扩展

在任意目录下克隆中文扩展地址

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

进入下载好的文件夹,把localizations文件夹内的Chinese-All.jsonChinese-English.json复制到stable-diffusion-webui\localizations目录下如下

启动web服务后点击Settings左侧点击User interface界面在界面里最下方的Localization (requires restart)选择Chinese-All或者Chinese-English点击界面最上方的黄色按钮Apply settings再点击右侧的Reload UI即可完成汉化。


汉化后的页面

附遇到的错误

  1. 报错RuntimeError: Couldn’t clone Stable Diffusion。
    解决办法手动clone
git clone https://github.com/Stability-AI/stablediffusion.git "/root/stable-diffusion-webui/repositories/stable-diffusion-stability-ai"
  1. 报错gnutls_handshake() failed: The TLS connection was non-properly terminated
    解决办法在执行时使用http而不是https替换
git clone https://github.com/Stability-AI/stablediffusion.git

git clone http://github.com/Stability-AI/stablediffusion.git
  1. 报错RuntimeError: Couldn’t install open_clip。安装open_clip失败
    解决办法进入launch.py文件找到openclip_package 部分代码修改对应部分代码为
openclip_package = os.environ.get('OPENCLIP_PACKAGE', "git+https://gitee.com/ufhy/open_clip.git@bb6e834e9c70d9c27d0dc3ecedeebeaeb1ffad6b")
阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
标签: 服务器Ubuntu