AUTOMATIC1111 / stable-diffusion-webui

Stable Diffusion web UI
GNU Affero General Public License v3.0
139.7k stars 26.48k forks source link

[Bug]: RuntimeError: Couldn't install torch. #16215

Open arkeence opened 2 months ago

arkeence commented 2 months ago

Checklist

What happened?

Screenshot 2024-07-15 163620 I have installed sd-v1-4.ckpt and GFPGAN 1.4. Now when I try to open it (WebUi-user.bat) it gives me this error. I tried to install manually but it doesn't work. I need it to work on AMD CPU.

image

Steps to reproduce the problem

  1. Open WebUi-user.bat

What should have happened?

It should have installed torch

What browsers do you use to access the UI ?

Mozilla Firefox

Sysinfo

The --dump-sysinfo dosen't work.

Console logs

venv "C:\Users\R\stable-diffusion-webui\venv\Scripts\Python.exe"
Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug  1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)]
Version: v1.9.4
Commit hash: feee37d75f1b168768014e4634dcb156ee649c05
Installing torch and torchvision
C:\Users\R\stable-diffusion-webui\venv\Scripts\python.exe: No module named pip
Traceback (most recent call last):
  File "C:\Users\R\stable-diffusion-webui\launch.py", line 48, in <module>
    main()
  File "C:\Users\R\stable-diffusion-webui\launch.py", line 39, in main
    prepare_environment()
  File "C:\Users\R\stable-diffusion-webui\modules\launch_utils.py", line 380, in prepare_environment
    run(f'"{python}" -m {torch_command}', "Installing torch and torchvision", "Couldn't install torch", live=True)
  File "C:\Users\R\stable-diffusion-webui\modules\launch_utils.py", line 115, in run
    raise RuntimeError("\n".join(error_bits))
RuntimeError: Couldn't install torch.
Command: "C:\Users\R\stable-diffusion-webui\venv\Scripts\python.exe" -m pip install torch==2.1.2 torchvision==0.16.2 --extra-index-url https://download.pytorch.org/whl/cu121
Error code: 1
Press any key to continue . . .

Additional information

I have windows 11

Aleszp commented 2 months ago

Can confirm on ARCH. Both when installed from AUR: aur/stable-diffusion-webui-git 1.9.4.r0.gfeee37d-2 (+0 0.00) (Installed: 1.9.4.r0.gfeee37d-3) and downloaded manually.

I attach log. Seems like some kind of available and required torch version mismatch? diffusion.log

pesado1 commented 2 months ago

I'm having the same problem

FiratUsta commented 2 months ago

Can confirm on ARCH. Both when installed from AUR: aur/stable-diffusion-webui-git 1.9.4.r0.gfeee37d-2 (+0 0.00) (Installed: 1.9.4.r0.gfeee37d-3) and downloaded manually.

I attach log. Seems like some kind of available and required torch version mismatch? diffusion.log

This is a separate issue from the original report. You are trying to run the script in a Python 3.12 environment, webui doesn't support that version, you need to install Python 3.10.6. If you don't want to downgrade your system python, just download the tarball of 3.10.6, make it and then replace

python_cmd="python3"

with

python_cmd="[PATH TO PYTHON3.10.6 EXECUTABLE]"

in webui.sh then run it and it should work.

arkeence commented 2 months ago

This is a separate issue from the original report (which I cannot help with). You are trying to run the script in a Python 3.12 environment, webui doesn't support that version, you need to install Python 3.10.6. If you don't want to downgrade your system python, just download the tarball of 3.10.6, make it and then replace

I've uninstalled Python 3.12 and installed 3.10.6 before installing Stable Diffusion.

But still is there a solution to fix my problem?

FiratUsta commented 2 months ago

This is a separate issue from the original report (which I cannot help with). You are trying to run the script in a Python 3.12 environment, webui doesn't support that version, you need to install Python 3.10.6. If you don't want to downgrade your system python, just download the tarball of 3.10.6, make it and then replace

I've uninstalled Python 3.12 and installed 3.10.6 before installing Stable Diffusion.

But still is there a solution to fix my problem?

My response was mostly aimed at Aleszp, as their logs suggest that they're using 3.12. Your case is different, you are correctly using 3.10.6, but looking at your logs it looks like you don't have pip? Can you open a cmd prompt and check the result of pip --version? If you don't get something like below, that means you don't have pip install which is necessary to install torch;

pip 22.2.1 from C:\Users\[USERNAME]\AppData\Local\Programs\Python\Python310\lib\site-packages\pip (python 3.10)

If you don't have pip, you can install it by looking at how-tos on the internet but the quickest and the easiest way is to:

  1. Run the Python 3.10.6 installer.
  2. Select the 'Modify' option.
  3. Make sure the checkbox next to 'pip' is selected, click next.
  4. Make sure 'Add Python to environment variables' is selected, click 'Install'.

When that's done, restart your PC and test pip --version again, if you see a version number you're good to go so you can run the batch file again and it should install.

pesado1 commented 2 months ago

This is a separate issue from the original report (which I cannot help with). You are trying to run the script in a Python 3.12 environment, webui doesn't support that version, you need to install Python 3.10.6. If you don't want to downgrade your system python, just download the tarball of 3.10.6, make it and then replace

I've uninstalled Python 3.12 and installed 3.10.6 before installing Stable Diffusion. But still is there a solution to fix my problem?

My response was mostly aimed at Aleszp, as their logs suggest that they're using 3.12. Your case is different, you are correctly using 3.10.6, but looking at your logs it looks like you don't have pip? Can you open a cmd prompt and check the result of pip --version? If you don't get something like below, that means you don't have pip install which is necessary to install torch;

pip 22.2.1 from C:\Users\[USERNAME]\AppData\Local\Programs\Python\Python310\lib\site-packages\pip (python 3.10)

If you don't have pip, you can install it by looking at how-tos on the internet but the quickest and the easiest way is to:

1. Run the Python 3.10.6 installer.

2. Select the 'Modify' option.

3. Make sure the checkbox next to 'pip' is selected, click next.

4. Make sure 'Add Python to environment variables' is selected, click 'Install'.

When that's done, restart your PC and test pip --version again, if you see a version number you're good to go so you can run the batch file again and it should install.

Hi, thanks for this, but will this affect the 3.12 install? just wanted to make sure before changing anything.

FiratUsta commented 2 months ago

Hi, thanks for this, but will this affect the 3.12 install? just wanted to make sure before changing anything.

If you have 3.12 installed on your system there are ways to install 3.10.6 without adding it to PATH and affecting your 3.12 install that is in PATH, or even just getting the 3.10.6 executable without installing it and pointing the program towards that. However, specifics depend on your system. I can help if you're running Linux (Basically just check my first response to this issue) but I'm not knowledgeable on how to do any of this on Windows sadly.

pesado1 commented 2 months ago

Hi, thanks for this, but will this affect the 3.12 install? just wanted to make sure before changing anything.

If you have 3.12 installed on your system there are ways to install 3.10.6 without adding it to PATH and affecting your 3.12 install that is in PATH, or even just getting the 3.10.6 executable without installing it and pointing the program towards that. However, specifics depend on your system. I can help if you're running Linux (Basically just check my first response to this issue) but I'm not knowledgeable on how to do any of this on Windows sadly.

thanks again, i got both, so i guess the 3.12 install messed up the paths. have no ideia why.. since both have the paths

image

Aleszp commented 1 month ago

Can confirm on ARCH. Both when installed from AUR: aur/stable-diffusion-webui-git 1.9.4.r0.gfeee37d-2 (+0 0.00) (Installed: 1.9.4.r0.gfeee37d-3) and downloaded manually. I attach log. Seems like some kind of available and required torch version mismatch? diffusion.log

This is a separate issue from the original report. You are trying to run the script in a Python 3.12 environment, webui doesn't support that version, you need to install Python 3.10.6. If you don't want to downgrade your system python, just download the tarball of 3.10.6, make it and then replace

python_cmd="python3"

with

python_cmd="[PATH TO PYTHON3.10.6 EXECUTABLE]"

in webui.sh then run it and it should work.

I actually have 3.10 installed (AUR version already installed it as dependence), the WebUI worked like 2-3 weeks ago, this week it suddenly stopped working (a bit of tactical googling lead me to this „identical for non-expert” issue).

Adding: export python_cmd="python3.10" to shell script which I use to start webui (with preferred parameters and in separate virtual console with screen utility) partially solved the issue for me - now proper version of python was utilised. However, as while pip was installed system wide, it was not detected by python3.10. Running: python3.10 -m ensurepip fixed the final issue, webui runs again.

If AUR package maintainer sees this: Maybe some package modyfication is needed?

Thank you @pesado1 your answers to both me and arkeence were essential for me to figure this out. EDIT: Redraft to improve clarity.