Install Torch with stable diffusion

#1835
by MIMA - opened

Hi everyone, i am strugling with running torch. This is the message i get everytime i try to run webui-user :
Anyone can help me please !!!

venv "C:\ai\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: 97bc0b9504572d2df80598d0b694703bcd626de6
Installing torch and torchvision
Traceback (most recent call last):
File "C:\ai\stable-diffusion-webui\launch.py", line 116, in
run(f'"{python}" -m {torch_command}', "Installing torch and torchvision", "Couldn't install torch")
File "C:\ai\stable-diffusion-webui\launch.py", line 54, in run
raise RuntimeError(message)
RuntimeError: Couldn't install torch.
Command: "C:\ai\stable-diffusion-webui\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: C:\ai\stable-diffusion-webui\venv\Scripts\python.exe: No module named pip

What worked for me with the exact same error was to delete venv folder as suggested here https://stackoverflow.com/questions/73817772/stable-diffusion-couldnt-install-torch-pip-version
for me the reason for this error was that becouse i use w7 still, pyton 3.10.6 wont install so i tryed previous versions but they didn't work but for some reason the installation process created that venv forlder anyway with wrong pyton version. After a little search i found a w7 compatible pyton 3.10.6 so installed it but this error showed in this topic apeared, and i solved it deleting venv folder completely. Then the instalation process proceded as spected.

Eremyr your solution worked thank you

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.

im having similar issues,, python wasn't working ( multiple paths and versions ) so I deleted all the old versions ... deleted the venv folder and rebooted - python started BUT -- can't I get torch going. Thinking of kicking python from 311 back to 3.10

I was having the same issue of timeout.
So I manually downloaded the pytorch from this link: https://download.pytorch.org/whl/cu117/torch-1.13.1%2Bcu117-cp310-cp310-win_amd64.whl
Copy the downloaded file into c:....\stablediffusion\venv\Scripts\ folder.
Open cmd in c:....\stablediffusion\venv\Scripts\ and then type "activate" (without commas)

You'll see the prompt change to (this means it's working)
(venv) c:....\stablediffusion\venv\Scripts\

Then give the following command and wait for a few seconds:
python.exe -m pip install --upgrade pip

Then give the following command:
pip install torch-1.12.1+cu113-cp310-cp310-win_amd64.whl

after this is finished, close this cmd window and go back to webui-user.bat file in the main directory.
Edit that and add --xformers after the following line:
It'll be like this
set COMMANDLINE_ARGS= --xformers

Now save that and run.

Downloading the pytorch part is where most of the errors come and now that is already done.
I hope this helps someone.

Note: I'm not a coder and I found this guide somewhere on Reddit.

Tried Omar fareed answer step by step works like magic.

I tired it too but as i write activate it says: activate' is not recognized as an internal or external command,
operable program or batch file.
Anyone can help?

maropilcz the steps Omar writes down should be performed in the venv/Scripts folder, where along with some python and pip executables there is a batch file named activate

Sign up or log in to comment