The machine used to deploy stable diffusion webui in this article is the Tencent cloud server linux system, centos7
One environment preparation
The advantage of using anaconda installation here is that you can easily install and manage software packages, and you can use different versions of Python and third-party software packages on the same system at the same time. If you need to install multiple systems and depend on different software versions, then install anaconda.
1. Download Anaconda
wget https://repo.anaconda.com/archive/Anaconda3-2023.03-1-Linux-x86_64.sh
If there is no wget, you can install yum install wget -y with the following command
2. Install Anaconda
Add execution permission: chmod +x Anaconda3-2023.03-1-Linux-x86_64.sh
Start execution : ./Anaconda3-2023.03-1-Linux-x86_64.sh
Follow the prompts, press Enter to press Enter, press yes to yes, and the following prompt will be displayed after the installation is successful
3. Create a Stable Diffusion virtual environment
When using Conda to manage the Python environment, a virtual environment base
named , which is shared globally, that is, the Python packages and libraries installed in this environment will affect all other virtual environments and the global environment on the system visible.
If you don't set it up, it will look like this after restarting
(base) [root@VM-0-4-centos ~]#
For clarity and to deploy other AI applications later, we create a separate virtual environment for Stable Diffusion.
Create a virtual environment: conda create -n sd python=3.10.6
、
View the environment list : conda evn list
install git
conda install git
Check the git version number
Two: stable-diffusion-webui installation and deployment
1. Download the code stable-diffusion-webui
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui
2. Start webu.sh
Switch to the stable-diffusion-webui directory
Method 1: Run bash webui.sh If you are a root user, you need to comment out the judgment about root permissions in webui.sh.
Method 2: The root user can also directly run bash webui.sh -f
Three: Common error messages
The next step is to solve the error message.
1、ERROR: This script must not be launched as root, aborting...
Add a parameter when starting: bash webui.sh -f so that it can be started as root.
If you find it troublesome, you can modify the webui.sh script code
2、No matching distribution found for torch==2.0.1
Collecting torch==2.0.1
Could not find a version that satisfies the requirement torch==2.0.1 (from versions: 1.0.0, 1.0.1, 1.0.1.post2, 1.1.0, 1.2.0, 1.3.0, 1.3.1, 1.4.0, 1.5.0, 1.5.1, 1.6.0, 1.7.0, 1.7.1, 1.8.0, 1.8.1, 1.9.0, 1.9.1, 1.10.0, 1.10.1, 1.10.2)
No matching distribution found for torch==2.0.1
You are using pip version 9.0.3, however version 23.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Traceback (most recent call last):
File "launch.py", line 38, in <module>
main()
File "launch.py", line 29, in main
prepare_environment()
File "/home/sdui/stable-diffusion-webui/modules/launch_utils.py", line 254, in prepare_environment
run(f'"{python}" -m {torch_command}', "Installing torch and torchvision", "Couldn't install torch", live=True)
File "/home/sdui/stable-diffusion-webui/modules/launch_utils.py", line 101, in run
raise RuntimeError("\n".join(error_bits))
RuntimeError: Couldn't install torch.
Command: "/home/sdui/stable-diffusion-webui/venv/bin/python3" -m pip install torch==2.0.1 torchvision==0.15.2 --extra-index-url https://download.pytorch.org/whl/cu118
Error code: 1
Troubleshooting:
1. The pip version is incorrect, resulting in an error when downloading the file
The old version of pip brought by default in conda is replaced with pip3
Uninstall: conda uninstall pip
Installation: conda install -c anaconda pip
Then run: bash webui.sh
2. If the download and installation cannot be completed automatically, you can install it manually
Check the CUDA version version
nvidia-smi
cat /usr/local/cuda/version.txt
Manually select version https://pytorch.org/get-started/locally/
Select the corresponding version, conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia
After running, start to enter the download of various dependencies
3. The git version is too low
Solution: conda install git
[notice] To update, run: pip install --upgrade pip
Installing gfpgan
Installing clip
Installing open_clip
Cloning Stable Diffusion into /app/stable-diffusion-webui/repositories/stable-diffusion-stability-ai...
Traceback (most recent call last):
File "/app/stable-diffusion-webui/launch.py", line 38, in <module>
main()
File "/app/stable-diffusion-webui/launch.py", line 29, in main
prepare_environment()
File "/app/stable-diffusion-webui/modules/launch_utils.py", line 288, in prepare_environment
git_clone(stable_diffusion_repo, repo_dir('stable-diffusion-stability-ai'), "Stable Diffusion", stable_diffusion_commit_hash)
File "/app/stable-diffusion-webui/modules/launch_utils.py", line 150, in git_clone
run(f'"{git}" -C "{dir}" checkout {commithash}', None, "Couldn't checkout {name}'s hash: {commithash}")
File "/app/stable-diffusion-webui/modules/launch_utils.py", line 101, in run
raise RuntimeError("\n".join(error_bits))
RuntimeError: Couldn't checkout {name}'s hash: {commithash}.
Command: "git" -C "/app/stable-diffusion-webui/repositories/stable-diffusion-stability-ai" checkout cf1d67a6fd5ea1aa600c4df58e5b47da45f6bdbf
Error code: 129
stderr: Unknown option: -C
usage: git [--version] [--help] [-c name=value]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]
4、报错:libGL.so.1: cannot open shared object file: No such file or directory
Solution: yum install mesa-libGL
Python 3.10.9 (main, Jan 11 2023, 15:21:40) [GCC 11.2.0] Version: v1.3.2 Commit hash: baf6946e06249c5af9851c60171692c44ef633e0 Cloning Taming Transformers into /app/stable-diffusion-webui/repositories/taming-transformers... Cloning K-diffusion into /app/stable-diffusion-webui/repositories/k-diffusion... Cloning CodeFormer into /app/stable-diffusion-webui/repositories/CodeFormer... Cloning BLIP into /app/stable-diffusion-webui/repositories/BLIP... Installing requirements for CodeFormer Installing requirements Launching Web UI with arguments: -f No module 'xformers'. Proceeding without it. Traceback (most recent call last): File "/app/stable-diffusion-webui/launch.py", line 38, in <module> main() File "/app/stable-diffusion-webui/launch.py", line 34, in main start() File "/app/stable-diffusion-webui/modules/launch_utils.py", line 330, in start import webui File "/app/stable-diffusion-webui/webui.py", line 49, in <module> from modules import shared, sd_samplers, upscaler, extensions, localization, ui_tempdir, ui_extra_networks, config_states File "/app/stable-diffusion-webui/modules/sd_samplers.py", line 1, in <module> from modules import sd_samplers_compvis, sd_samplers_kdiffusion, shared File "/app/stable-diffusion-webui/modules/sd_samplers_compvis.py", line 9, in <module> from modules import sd_samplers_common, prompt_parser, shared File "/app/stable-diffusion-webui/modules/sd_samplers_common.py", line 5, in <module> from modules import devices, processing, images, sd_vae_approx, sd_samplers, sd_vae_taesd File "/app/stable-diffusion-webui/modules/processing.py", line 11, in <module> import cv2 File "/app/stable-diffusion-webui/venv/lib/python3.10/site-packages/cv2/__init__.py", line 181, in <module> bootstrap() File "/app/stable-diffusion-webui/venv/lib/python3.10/site-packages/cv2/__init__.py", line 153, in bootstrap native_module = importlib.import_module("cv2") File "/root/anaconda3/envs/sd/lib/python3.10/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ImportError: libGL.so.1: cannot open shared object file: No such file or directory
Four: Conda commonly used commands
1. Create environment:
conda create --name 环境名称
Purpose: Used to create a new Conda environment, you can specify the name of the environment.
2. Activate the environment:
conda activate 环境名称
Purpose: Used to activate the Conda environment with the specified name.
3. Disable the environment:
conda deactivate
Purpose: Used to deactivate the currently activated Conda environment.
4. Delete the environment:
conda remove --name 环境名称 --all
Purpose: It is used to delete the Conda environment with the specified name, and
--all
the parameter indicates to delete the environment and all its installed packages.5. Installation package:
conda install 包名称
Purpose: Used to install the specified package in the current environment.
6. Upgrade package:
conda update 包名称
Purpose: Used to update the version of an installed package.
7. Uninstall the package:
conda remove 包名称
Purpose: Used to uninstall the specified package from the current environment.
8. View installed packages:
conda list
Purpose: Used to list installed packages in the current environment.
9. Search package:
conda search 包名称
Purpose: Used to search for specified packages in the Conda repository.
10. Create an environment configuration file:
conda env export > environment.yaml
Purpose: It is used to export the configuration of the current environment into a YAML file for copying or rebuilding the environment elsewhere.
11. View configuration information:
conda config --show
Display the current Conda configuration information, including common configuration, environment configuration and user configuration.
12. View the value of a configuration item:
conda config --show 配置项
Display the current value of a specific configuration item, for example:
conda config --show channels
used to display the currently configured channel list.13. Set the value of the configuration item:
conda config --set 配置项=值
Example:
conda config --set channels conda-forge
for setting the channel to conda-forge.14. Add channel:
conda config --add channels 通道名称
Adds a new channel to the configuration to make Conda prioritize that channel when searching and installing packages.
15. Remove the channel:
conda config --remove channels 通道名称
Removes the specified channel from the configuration so that Conda no longer uses that channel.
16. List all channels:
conda config --get channels
List all configured channels in the current configuration.
17. Reset configuration items:
conda config --remove-key 配置项
Reset the value of the specified configuration item to the default value.
18. Edit the configuration file:
conda config --edit
Opening the configuration file for manual editing allows modification of various configuration options.
19. Create an environment with a specified version:
conda create --name myenv python=3.10.6
20. Export and import environment configuration from environment
Export environment configuration
conda env export --name myenv --file environment.yaml
Import environment configuration
conda env create --file environment.yaml
21. Create a clone of the virtual environment:
conda create --name myclone --clone myenv