You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Stable Diffusion安装torch失败求助:重装对应Python版本仍无效

Stable Diffusion部署中Torch安装失败的解决方法

报错重现

执行launch.py时触发以下错误:

[notice] A new release of pip available: 22.2.2 -> 23.0.1
[notice] To update, run: D:\AIART\stable-diffusion-webui\venv\Scripts\python.exe -m pip install --upgrade pip
Traceback (most recent call last):
  File "D:\AIART\stable-diffusion-webui\launch.py", line 360, in <module>
    prepare_environment()
  File "D:\AIART\stable-diffusion-webui\launch.py", line 269, in prepare_environment
    run(f'"{python}" -m {torch_command}', "Installing torch and torchvision", "Couldn't install torch", live=True)
  File "D:\AIART\stable-diffusion-webui\launch.py", line 89, in run
    raise RuntimeError(f"""{errdesc or 'Error running command'}.
RuntimeError: Couldn't install torch.
Command: "D:\AIART\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: 2

解决步骤

  • 升级pip:先执行命令更新pip到指定版本,旧版本pip可能存在兼容性问题
    D:\AIART\stable-diffusion-webui\venv\Scripts\python.exe -m pip install --upgrade pip
    
  • 手动激活虚拟环境并安装:
    1. 打开命令行,进入虚拟环境脚本目录:cd D:\AIART\stable-diffusion-webui\venv\Scripts
    2. 激活虚拟环境:activate(Windows系统)
    3. 手动执行安装命令,添加国内镜像可加速下载:
      pip install torch==1.13.1+cu117 torchvision==0.14.1+cu117 --extra-index-url https://download.pytorch.org/whl/cu117 -i https://pypi.tuna.tsinghua.edu.cn/simple
      
  • 检查CUDA兼容性:确认显卡支持CUDA 11.7,且已安装对应版本的CUDA Toolkit。若显卡不支持该版本,更换为匹配的torch版本(如cuda116或CPU版本)
  • 清除pip缓存:执行pip cache purge清理损坏的缓存文件,避免缓存阻碍安装
  • 重新运行launch.py:完成上述操作后,回到Stable Diffusion根目录,重新启动部署脚本

内容的提问来源于stack exchange,提问作者rBreach

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 12:05:32