ERROR: No matching distribution found for torch==2.0.1解决方案

发布时间:2023年12月29日

大家好,我是水滴~~

本文主要介绍在安装 stable-diffusion-webui 时出现的 ERROR: No matching distribution found for torch==2.0.1 问题的解决方案,希望能对你有所帮助。

《Python入门核心技术》专栏总目录?点这里


问题描述

在安装 stable-diffusion-webui 过程中出现ERROR: No matching distribution found for torch==2.0.1错误,详细错误如下:

ERROR: Could not find a version that satisfies the requirement torch==2.0.1 (from versions: none)
ERROR: No matching distribution found for torch==2.0.1
Traceback (most recent call last):
  File "D:\StableDiffusion\stable-diffusion-webui\launch.py", line 48, in <module>
    main()
  File "D:\StableDiffusion\stable-diffusion-webui\launch.py", line 39, in main
    prepare_environment()
  File "D:\StableDiffusion\stable-diffusion-webui\modules\launch_utils.py", line 378, in prepare_environment
    run(f'"{python}" -m {torch_command}', "Installing torch and torchvision", "Couldn't install torch", live=True)
  File "D:\StableDiffusion\stable-diffusion-webui\modules\launch_utils.py", line 116, in run
    raise RuntimeError("\n".join(error_bits))
RuntimeError: Couldn't install torch.
Command: "D:\StableDiffusion\stable-diffusion-webui\venv\Scripts\python.exe" -m pip install torch==2.0.1 torchvision==0.15.2 --extra-index-url https://download.pytorch.org/whl/cu118
Error code: 1

解决方案

这跟 Python 的版本有关系,在当前版本中找不到 PyTorch 2.0.1 版本。官方要求的版本是 Python 3.10.6,你可以检查你的 Python 版本是否正确。

注意:在运行 webui-user.bat 时会在stable-diffusion-webui项目中创建一个 Python 虚拟环境,所以检查版本应该使用下面命令:
D:\StableDiffusion\stable-diffusion-webui\venv\Scripts\python.exe --version

如果版本不正确,请安装正确的 Python 3.10.6 版本。

安装好 Python 后,编辑 webui-user.bat,在 set PYTHON=后面指定 Python 可执行文件的路径,如下图:

在这里插入图片描述

然后删除 stable-diffusion-webui 目录下的 venv目录,重新运行 webui-user.bat,这样就能正常下载安装 PyTorch 了,如下图:

在这里插入图片描述

离线安装 PyTorch

如果你觉得上面方法安装的速度慢,也可以先使用迅雷下载下来,打开官方下载页:https://download.pytorch.org/whl/torch/,找到要下载的版本,右击使用迅雷下载。如下图:

在这里插入图片描述

或者直接下载:torch-2.0.1+cu118-cp310-cp310-win_amd64.whl

下载完后,可使用下成命令安装:

D:\StableDiffusion\stable-diffusion-webui\venv\Scripts\python.exe -m pip install D:\StableDiffusion\torch-2.0.1+cu118-cp310-cp310-win_amd64.whl

文章来源:https://blog.csdn.net/weixin_67276852/article/details/135282712
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。