stable-diffusion-webui icon indicating copy to clipboard operation
stable-diffusion-webui copied to clipboard

[Bug]: RuntimeError: Couldn't Install Torch

Open walrusthief opened this issue 2 years ago • 15 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues and checked the recent builds/commits

What happened?

Running web-ui.bat throws up this error:

venv "C:\stable-diffusion-webui-master\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)] Commit hash: Installing torch and torchvision Traceback (most recent call last): File "C:\stable-diffusion-webui-master\launch.py", line 251, in prepare_enviroment() File "C:\stable-diffusion-webui-master\launch.py", line 169, in prepare_enviroment run(f'"{python}" -m {torch_command}', "Installing torch and torchvision", "Couldn't install torch") File "C:\stable-diffusion-webui-master\launch.py", line 34, in run raise RuntimeError(message) RuntimeError: Couldn't install torch. Command: "C:\stable-diffusion-webui-master\venv\Scripts\python.exe" -m pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 --extra-index-url https://download.pytorch.org/whl/cu113 Error code: 1 stdout: stderr: Traceback (most recent call last): File "C:\Users\Sparky\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\Sparky\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in run_code exec(code, run_globals) File "C:\stable-diffusion-webui-master\venv\lib\site-packages\pip_main.py", line 29, in from pip._internal.cli.main import main as main File "C:\stable-diffusion-webui-master\venv\lib\site-packages\pip_internal_init.py", line 3, in import pip._internal.utils.inject_securetransport # noqa ValueError: source code string cannot contain null bytes

I've tried uninstalling torch, manually installing it, removing it again, updating python to version 11, then downgrading it first to 10.8, then to 10.6.

Steps to reproduce the problem

  1. Go to root stable-diffusion-webui-master
  2. Click webui-user.bat or webui.bat
  3. Error Codes Ensue

What should have happened?

It should have installed Torch and Torchvision and moved on to the next step.

Commit where the problem happens

It says ?

What platforms do you use to access UI ?

Windows

What browsers do you use to access the UI ?

Microsoft Edge

Command Line Arguments

No response

Additional information, context and logs

No response

walrusthief avatar Nov 04 '22 19:11 walrusthief

I have the same issue when trying to run webui.bat

spaciousmind avatar Nov 06 '22 01:11 spaciousmind

managed to fix this ---- in my case it was an issue with my version of miniconda, I uninstalled it, restarted my computer, installed python 3.10 with all the admin privileges and environment variables and removed the venv folder in my stable diffusion dir, then ran webui.bat again and waited a long time and it all worked :) I followed this answer here https://stackoverflow.com/a/74262982/12831107

spaciousmind avatar Nov 06 '22 02:11 spaciousmind

Can someone help with this issue please?

Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug 1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)] Commit hash: 828438b4a190759807f9054932cae3a8b880ddf1 Traceback (most recent call last): File "C:\Ai\Stable-Diffusion\stable-diffusion-webui\launch.py", line 250, in prepare_enviroment() File "C:\Ai\Stable-Diffusion\stable-diffusion-webui\launch.py", line 174, in prepare_enviroment run_python("import torch; assert torch.cuda.is_available(), 'Torch is not able to use GPU; add --skip-torch-cuda-test to COMMANDLINE_ARGS variable to disable this check'") File "C:\Ai\Stable-Diffusion\stable-diffusion-webui\launch.py", line 58, in run_python return run(f'"{python}" -c "{code}"', desc, errdesc) File "C:\Ai\Stable-Diffusion\stable-diffusion-webui\launch.py", line 34, in run raise RuntimeError(message) RuntimeError: Error running command. Command: "C:\Ai\Stable-Diffusion\stable-diffusion-webui\venv\Scripts\python.exe" -c "import torch; assert torch.cuda.is_available(), 'Torch is not able to use GPU; add --skip-torch-cuda-test to COMMANDLINE_ARGS variable to disable this check'" Error code: 1 stdout: stderr: C:\Ai\Stable-Diffusion\stable-diffusion-webui\venv\lib\site-packages\torch\cuda_init_.py:83: UserWarning: CUDA initialization: CUDA driver initialization failed, you might not have a CUDA gpu. (Triggered internally at ..\c10\cuda\CUDAFunctions.cpp:109.) return torch._C._cuda_getDeviceCount() > 0 Traceback (most recent call last): File "", line 1, in AssertionError: Torch is not able to use GPU; add --skip-torch-cuda-test to COMMANDLINE_ARGS variable to disable this check

reecelightning avatar Nov 24 '22 16:11 reecelightning

If anyone tried all the options and still can't fix it yet, try this: after uninstalling python there are still some files at users/yourusername/AppData. I installed and uninstalled for like 6-7 times with all different options like trying a different HDD, different root name etc. and still gave "Couldn't install torch" error. I don't know how, but it worked for me when I deleted all Python and pip files at AppData and then tried a clean installation of Python and Stable Diffusion WebUI. Good luck.

ozankalinagac avatar Nov 25 '22 16:11 ozankalinagac

For anyone else running into this error: you have to use exactly Python 3.10.6 (as of December 2022).

Torch doesn't support newer versions so if you did the obvious thing and installed the latest Python (3.11 right now) then it won't work, or give you any helpful error messages.

This is probably very obvious to people who use Python a lot and not at all obvious to the rest of us.

looeee avatar Dec 16 '22 22:12 looeee

For anyone else running into this error: you have to use exactly Python 3.10.6 (as of December 2022).

This works, but just to add to this, you also need to delete the 'venv' folder in the root directory of your sdwebui install (ty @spaciousmind). Because when you run the webui.bat file, it will create that folder and it's contents, based on the current version of python you are using.

designerjason avatar Dec 30 '22 11:12 designerjason

Good afternoon, I would like to ask if you have managed to solve the problem you are facing? Thank you in advance for the answer!

VladislavIgoshin avatar Jan 14 '23 10:01 VladislavIgoshin

Deleting venv and rebooting did it for me, didn't need to uninstall or reinstall Python.

Straafe avatar Jan 20 '23 01:01 Straafe

For anyone else running into this error: you have to use exactly Python 3.10.6 (as of December 2022).

This works, but just to add to this, you also need to delete the 'venv' folder in the root directory of your sdwebui install (ty @spaciousmind). Because when you run the webui.bat file, it will create that folder and it's contents, based on the current version of python you are using.

Thank you, it works!

SyrexBlack avatar Feb 19 '23 07:02 SyrexBlack

For anyone else running into this error: you have to use exactly Python 3.10.6 (as of December 2022).

Torch doesn't support newer versions so if you did the obvious thing and installed the latest Python (3.11 right now) then it won't work, or give you any helpful error messages.

This is probably very obvious to people who use Python a lot and not at all obvious to the rest of us.

This worked for me, also don't forget to delete venv folder, also don't forget to add it to the environment variables > system variables > path

JungleHam avatar Mar 17 '23 16:03 JungleHam

Help i tried every sollution i could find but nothing works

I tried downloading differents version of python making sure to delete the previous one before and the pip folder in AppData and deleting the venv folder too but it's still wont work here is my error message :

venv "D:\AI\invokeai\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)] Commit hash: a9fed7c364061ae6efb37f797b6b522cb3cf7aa2 Installing torch and torchvision D:\AI\invokeai\stable-diffusion-webui\venv\Scripts\python.exe: No module named pip Traceback (most recent call last): File "D:\AI\invokeai\stable-diffusion-webui\launch.py", line 380, in prepare_environment() File "D:\AI\invokeai\stable-diffusion-webui\launch.py", line 284, in prepare_environment run(f'"{python}" -m {torch_command}', "Installing torch and torchvision", "Couldn't install torch", live=True) File "D:\AI\invokeai\stable-diffusion-webui\launch.py", line 97, in run raise RuntimeError(f"""{errdesc or 'Error running command'}. RuntimeError: Couldn't install torch. Command: "D:\AI\invokeai\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

Yartez avatar Mar 19 '23 00:03 Yartez

You could try this: https://stackoverflow.com/a/75728535

Straafe avatar Mar 19 '23 01:03 Straafe

You could try this: https://stackoverflow.com/a/75728535

didn't work thanks for the help tho

Yartez avatar Mar 20 '23 12:03 Yartez

assuming you actually used the link to the correct 3.10 python install that automatic1111 provides ...
( https://www.python.org/ftp/python/3.10.6/python-3.10.6-amd64.exe ) and that the issues is not also conflicting 3.11 (or other) python versions in the "environment variables" sections of your windows configuration, the actual solution is editing the PYVENV.CFG file in the VENV Folder to say something like the following (replace paths with YOUR/ACTUAL/PYTHON310/EXE/PATH) :

PYVENV.CFG (edited to remove 3.11 references): home = C:\Users\YOURUSER\AppData\Local\Programs\Python\Python310
include-system-site-packages = false version = 3.10 executable = C:\Users\YOURUSER\AppData\Local\Programs\Python\Python310\python.exe command = C:\Users\YOURUSER\AppData\Local\Programs\Python\Python310\python.exe -m venv C:\Users\YOURUSER\YOURstable-diffusion2FOLDER\venv

---------END FILE-------------- DO THAT. re run webui-user.bat and it should download pytorch and you're good.

ifiwasakid avatar Apr 22 '23 18:04 ifiwasakid

This fixed it for me

bfenty avatar Apr 24 '23 19:04 bfenty

For anyone else running into this error: you have to use exactly Python 3.10.6 (as of December 2022).

This works, but just to add to this, you also need to delete the 'venv' folder in the root directory of your sdwebui install (ty @spaciousmind). Because when you run the webui.bat file, it will create that folder and it's contents, based on the current version of python you are using.

omg this fixed it for me :) deleting the folder! it rebuilds it with the correct info etc

testokayman123 avatar Mar 09 '24 06:03 testokayman123