---
title: "Stable Diffusion｜安装过程中常见报错解决方法"
canonical: "https://96p.net/articles/qwen/47092/Stable+Diffusion%EF%BD%9C%E5%AE%89%E8%A3%85%E8%BF%87%E7%A8%8B%E4%B8%AD%E5%B8%B8%E8%A7%81%E6%8A%A5%E9%94%99%E8%A7%A3%E5%86%B3%E6%96%B9%E6%B3%95"
---

# Stable Diffusion｜安装过程中常见报错解决方法

> 发布时间：2023-08-06
> 栏目：通义千问

[title-plane title="前言"]

大家可能在安装部署Stable Diffusion WebUI过程中遇到各种各样的问题，本站已对所有问题进行汇总整理，而且教大家如何去查看报错。解决常见的Installing gfpgan、BLIP错误、显存不足等各种各样的花式问题，希望大家在看完此文章之后，都能够顺利解决各自所遇到的问题。

[/title-plane]

&nbsp;
<h2>查看报错</h2>
<p id="dde3fe09-57f3-4594-9fe1-a60f77188896">在你安装时可能经常遇到各种各样的问题，但是对于一堆陌生的英文和各种各样的错误，大家可能经常无从下手，下面我将会教大家如何查看报错，就像这个截图这样：</p>

<pre class="corepress-code-pre"><code>C:\X65.NET\stable-diffusion-webui&gt;webui-user.bat
venv “C:\X65.NET\stable-diffusion-webui\venv\Scripts\Python.exe”
Python 3.10.10 | packaged by Anaconda, Inc. | (main, Mar 21 2023, 18:39:17) [MSC v.1916 64 bit (AMD64)]
Commit hash: 955df7751eef11bb7697e2d77f6b8a6226b21e13
Installing clip
Installing open_clip
Cloning Stable Diffusion into C:\X65.NET\stable-diffusion-webui\repositories\stable-diffusion-stability-ai…
Cloning Taming Transformers into C:\X65.NET\stable-diffusion-webui\repositories\taming-transformers…
Cloning K-diffusion into C:\X65.NET\stable-diffusion-webui\repositories\k-diffusion…
Cloning CodeFormer into C:\X65.NET\stable-diffusion-webui\repositories\CodeFormer…
Traceback (most recent call last):
File “C:\X65.NET\stable-diffusion-webui\launch.py”, line 351, in
prepare_environment()
File “C:\X65.NET\stable-diffusion-webui\launch.py”, line 287, in prepare_environment
git_clone(codeformer_repo, repo_dir(‘CodeFormer’), “CodeFormer”, codeformer_commit_hash)
File “C:\X65.NET\stable-diffusion-webui\launch.py”, line 151, in git_clone
run(f'”{git}” clone “{url}” “{dir}”‘, f”Cloning {name} into {dir}…”, f”Couldn’t clone {name}”)
File “C:\X65.NET\stable-diffusion-webui\launch.py”, line 97, in run
raise RuntimeError(message)
RuntimeError: Couldn’t clone CodeFormer.
Command: “git” clone “https://github.com/sczhou/CodeFormer.git” “C:\X65.NET\stable-diffusion-webui\repositories\CodeFormer”
Error code: 128
stdout:
stderr: Cloning into ‘C:\X65.NET\stable-diffusion-webui\repositories\CodeFormer’…</code></pre>
<p id="21ea0b3b-1378-4134-8602-b8599591af54">我们先看一下第一行内容<code>(base) C:\X65.NET\stable-diffusion-webui&gt;webui-user.bat</code>，前面的(base)是使用conda创建的虚拟环境名称，代表我们目前正在使用哪一个虚拟环境，很显然这与本站所提供的教程是不一致的，正常来说应该是<code>(D:\X65.NET\stable-diffusion-webui\automatic)</code>，这一串路径就是虚拟环境的名称。</p>
<p id="21ec851c-cfa0-47a3-81b9-f3dc8e8ea1e1">第5行和第6行分别是<code>Installing clip</code>和<code>Installing open_clip</code>，这是两个依赖库。这里没有报错，因为后面是是Cloning一些其它的依赖库。</p>
<p id="2ce9c4f9-f20a-4b99-a696-1e96f69e000d">第11行<code>Traceback (most recent call last):</code>，这就是代表出现问题了，我们在出现问题的前一行中可以看到内容为<code>Cloning CodeFormer into C:\X65.NET\stable-diffusion-webui\repositories\CodeFormer…</code>，这就是代表是一步出错了。</p>
所以普遍情况下，找到最后的3行就能知晓核心的错误原因了。

&nbsp;
<h2>网络问题</h2>
<p id="b6b1faf6-3b1c-4573-ae09-acf177af8078">本部分内容基本都是因为网络问题，大部分安装问题可以通过使用国内镜像源来解决。</p>
<p id="5de0d54c-dd66-420c-a140-a7bb1d639c05">例如：我们需要在执行安装requirements.txt文件时，我们可以尝试使用<code>pip install -i https://mirrors.aliyun.com/pypi/simple/ -r D:/X65.NET/stable-diffusion-webui/requirements.txt</code>。</p>
<p id="dc4b30ab-7788-42d5-b0d6-ca047c2a52e2">这段代码可以理解为不使用官方下载地址，而是国内阿里云的镜像地址下载相关依赖组件。如果阿里云的速度不行，各位同学也可以搜“PIP 国内镜像” 进行对应的替换，当然也可以寻找班主任协助。</p>
&nbsp;
<h2 class="wp-block-heading" id="pypi错误">PyPI错误</h2>
当我们遇到这类型的代码 就意味着PyPI的错误，
<pre class="corepress-code-pre"><code>note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
Encountered error while generating package metadata.
See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.</code></pre>
&nbsp;

虽然提示中是代码包的问题而非PIP的问题，而是PyPI元数据包有问题，但依然可以尝试执行<code>pip cache purge</code>清理缓存。

&nbsp;
<h2>组件安装失败</h2>
这类型问题是特别容易遇到的，包括了GFPGAN、xformers、open_clip、CodeFormer等核心组件，但凡失败一个就会导致SD失败，虽然最终都是导致无法安装SD但其过中原因还是存在差异，需要根据实际情况处理：
<h3 class="wp-block-heading" id="组件不匹配">组件不匹配</h3>
<p id="a389b300-27bd-4385-ae63-2d21272a54f3">这个错误信息意味着在当前使用的Python环境下，没有找到匹配的<code><strong>opencv-contrib-python</strong></code>版本。这可能是因为在PyPI上没有发布所需的版本或版本不兼容。请尝试使用<code><strong>pip search</strong></code>命令来搜索可用的版本，并尝试安装兼容的版本。</p>
<p id="82f8d1f8-2866-4bb0-b9c9-373c70da3c66">按道理来说，如果根据教程来安装是不会出现这个问题的，尽量删除后从头来过，严格遵守每一步。</p>

<pre class="corepress-code-pre"><code>ERROR: Could not find a version that satisfies the requirement opencv-contrib-python (from versions: none)
ERROR: No matching distribution found for opencv-contrib-python</code></pre>
&nbsp;
<h3 class="wp-block-heading" id="未找到pip">未找到pip</h3>
<pre class="corepress-code-pre"><code>venv “D:\X65.NET\stable-diffusion-webui\venv\Scripts\Python.exe”
Python 3.10.10 (tags/v3.10.10:aad5f6a, Feb 7 2023, 17:20:36) [MSC v.1929 64 bit (AMD64)]
Commit hash: 4c1ad743e3baf1246db0711aa0107debf036a12b
Installing torch and torchvision
D:\X65.NET\stable-diffusion-webui\venv\Scripts\python.exe: No module named pip
Traceback (most recent call last):
File “D:\X65.NET\stable-diffusion-webui\launch.py”, line 351, in
prepare_environment()
File “D:\X65.NET\stable-diffusion-webui\launch.py”, line 253, in prepare_environment
run(f'”{python}” -m {torch_command}’, “Installing torch and torchvision”, “Couldn’t install torch”, live=True)
File “D:\X65.NET\stable-diffusion-webui\launch.py”, line 81, in run
raise RuntimeError(f”””{errdesc or ‘Error running command’}.
RuntimeError: Couldn’t install torch.
Command: “D:\X65.NET\stable-diffusion-webui\venv\Scripts\python.exe” -m pip install torch==1.13.1+cu117 torchvision==0.14.1+cu117 –extra-index-url https://download.pytorch.org/whl/cu117
Error code: 1</code></pre>
<p id="d3c290e7-c81e-41ff-88fa-f89b01062d82">根据错误日志，似乎在运行<span> </span><code><strong>launch.py</strong></code><span> </span>文件尝试安装 torch 和 torchvision。然而，这个命令在运行时出现了错误，错误信息是<span> </span><code><strong>No module named pip</strong></code>。</p>
<p id="67b8b762-15c3-480d-8449-383b49066d0c">这可能是因为 Python 环境中没有安装 pip，所以在运行 pip 命令时出现了问题。</p>
<p id="60546952-4531-4798-a93b-a4a126edaff2">你可以尝试先安装 pip，然后再运行<span> </span><code><strong>launch.py</strong></code>。你可以使用以下命令来安装 pip：</p>

<pre class="corepress-code-pre"><code>python get-pip.py</code></pre>
这应该会在你的 Python 环境中安装 pip。然后你可以再次运行启动文件即可。

&nbsp;

&nbsp;
<h3>xformers</h3>
<pre class="corepress-code-pre"><code>No module ‘xformers’. Proceeding without it.</code></pre>
首先这个情况的提示是影响SD的运行的，每次启动时显示如上内容，这并不算错误。可以手动更改为支持。这个库的主要作用是可以加速生成图像，但有时候安装过后速度反而下降，所以建议保持即可，不用理会。

&nbsp;
<h3 class="wp-block-heading" id="pip升级">PIP升级</h3>
<pre class="corepress-code-pre"><code>[notice] A new release of pip available: 22.3.1 -&gt; 23.0.1
[notice] To update, run: D:\X65.NET\stable-diffusion-webui\venv\Scripts\python.exe -m pip install –upgrade pip</code></pre>
<p id="5b9fe476-d5f7-4d66-89e0-d7c0759e2b95">PIP需要升级，解决方法很简单，直接复制执行你的电脑所给出的代码即可。例如我们复制<code>run:</code>后面的全部，然后在CMD中执行即可，例如：</p>

<pre class="corepress-code-pre"><code>D:\X65.NET\stable-diffusion-webui\venv\Scripts\python.exe -m pip install –upgrade pip</code></pre>
注意力，每位同学的地址是存在差异的，不能一概而论，需要根据自己的目录来修改

&nbsp;
<h2 class="wp-block-heading" id="显存不足">显存不足</h2>
<pre class="corepress-code-pre"><code>(base) D:\X65.NET\stable-diffusion-webui&gt;webui-user.bat
venv “D:\X65.NET\stable-diffusion-webui\venv\Scripts\Python.exe”
Python 3.10.9 | packaged by Anaconda, Inc. | (main, Mar 8 2023, 10:42:25) [MSC v.1916 64 bit (AMD64)]
Commit hash: a9fed7c364061ae6efb37f797b6b522cb3cf7aa2
Installing requirements for Web UI
Launching Web UI with arguments:
No module ‘xformers’. Proceeding without it.
Loading weights [ad2a33c361] from D:\X65.NET\stable-diffusion-webui\models\Stable-diffusion\v2-1_768-ema-pruned.ckptCreating model from config: D:\X65.NET\stable-diffusion-webui\repositories\stable-diffusion-stability-ai\configs\stable-diffusion\v2-inference-v.yaml
LatentDiffusion: Running in v-prediction mode
DiffusionWrapper has 865.91 M params.
loading stable diffusion model: OutOfMemoryError
Traceback (most recent call last):
File “D:\X65.NET\stable-diffusion-webui\webui.py”, line 136, in initialize
modules.sd_models.load_model()
File “D:\X65.NET\stable-diffusion-webui\modules\sd_models.py”, line 441, in load_model
sd_model.to(shared.device)
File “D:\X65.NET\stable-diffusion-webui\venv\lib\site-packages\pytorch_lightning\core\mixins\device_dtype_mixin.py”, line 113, in to
return super().to(*args, **kwargs)
File “D:\X65.NET\stable-diffusion-webui\venv\lib\site-packages\torch\nn\modules\module.py”, line 989, in to
return self._apply(convert)
File “D:\X65.NET\stable-diffusion-webui\venv\lib\site-packages\torch\nn\modules\module.py”, line 641, in _apply
module._apply(fn)
File “D:\X65.NET\stable-diffusion-webui\venv\lib\site-packages\torch\nn\modules\module.py”, line 641, in _apply
module._apply(fn)
File “D:\X65.NET\stable-diffusion-webui\venv\lib\site-packages\torch\nn\modules\module.py”, line 641, in _apply
module._apply(fn)
[Previous line repeated 4 more times]
File “D:\X65.NET\stable-diffusion-webui\venv\lib\site-packages\torch\nn\modules\module.py”, line 664, in _apply
param_applied = fn(param)
File “D:\X65.NET\stable-diffusion-webui\venv\lib\site-packages\torch\nn\modules\module.py”, line 987, in convert
return t.to(device, dtype if t.is_floating_point() or t.is_complex() else None, non_blocking)
torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 2.00 GiB total capacity; 1.66 GiB already allocated; 0 bytes free; 1.71 GiB reserved in total by PyTorch) If reserved memory is &gt;&gt; allocated memory try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF

Stable diffusion model failed to load, exiting
请按任意键继续. . .</code></pre>
根据错误信息显示，Stable Diffusion 模型加载时遇到了 CUDA 显存不足的错误，简单点来说就是显卡不行，没有足够的显存空间分配给该模型。普遍而言 6G 的显卡现存能基本满足，更换显卡也能解决上述问题。但既然看到这篇文章，就给大家演示不换换显卡、不买新显卡的办法：开启低显存模式，开启低显存模式的方法如下。

&nbsp;
<h3>修改配置</h3>
<p id="d256dc2d-6d53-45bb-8d51-a6f123e553d3">在stable-diffusion-webui文件夹下找到webui-user.bat，用文本或代码编辑器打开该文件夹，可以看到如下内容。</p>
我们只需要修改<code>set COMMANDLINE_ARGS=</code>部分即可，该部分内容是启动参数。如果你的显卡显存不足4G，可以在<code>set COMMANDLINE_ARGS=</code>的后面添加参数<code>–lowvram –always-batch-cond-uncond</code>之后保存即可，变更之后的文件内容如下。
<pre class="corepress-code-pre"><code>@echo off

set PYTHON=
set GIT=
set VENV_DIR=
set COMMANDLINE_ARGS=–lowvram –always-batch-cond-uncond

call webui.bat</code></pre>
&nbsp;
<p id="a31f567c-f76a-490e-9871-8cea37a44751">如果你的显卡大于4G又小于6G显存，可以在<code>set COMMANDLINE_ARGS=</code>的后面添加参数<code>–precision full –no-half –medvram</code>之后保存即可，变更之后的文件内容如下。</p>

<pre class="enlighter-clipboard">@echo off

set PYTHON=
set GIT=
set VENV_DIR=
set COMMANDLINE_ARGS=–precision full –no-half –medvram

call webui.bat</pre>
<div class="enlighter-default enlighter-v-standard enlighter-t-atomic enlighter-l-generic enlighter-hover enlighter-linenumbers enlighter-overflow-scroll ">
<div class="enlighter-code">
<div class="enlighter">
<div class=""></div>
</div>
</div>
</div>
<h3>重新启动</h3>
下次使用SD，双击 webui-user.bat 即可

&nbsp;

<img src="https://www.96p.net/wp-content/uploads/2023/06/tmp5lln48eq.png" alt="" width="768" height="512" class="aligncenter size-full wp-image-35" />
