How to install Stable Diffusion on Windows (AUTOMATIC1111)

496,693 views
Updated Categorized as Tutorial Tagged , 426 Comments on How to install Stable Diffusion on Windows (AUTOMATIC1111)

We will go through how to download and install the popular Stable Diffusion software AUTOMATIC1111 on Windows step-by-step.

Stable Diffusion is a text-to-image AI that can be run on a consumer-grade PC with a GPU. After this tutorial, you can generate AI images on your own PC.

Systems requirements

Your PC should run Windows 10 or higher with a discrete Nvidia video card (GPU) with 4 GB VRAM or more. An integrated GPU will not work.

If your PC does not meet these requirements, alternatives are

Installing on AMD GPU

AUTOMATIC1111 does not officially support AMD GPUs, but it is possible to make it work if you are tech-savvy or willing to try. See the unofficial installation guide on the official GitHub page.

Installation steps

Step 1: Install python

You will need Python 3.10.6. (DON’T use Python 3.11 or newer) There are two ways to install Python on Windows

Option 1: Install from the Microsoft store.

Option 2: Use the 64-bit Windows installer provided by the Python website. (If you use this option, make sure to select “Add Python to 3.10 to PATH“)

I recommend installing it from the Microsoft store.

First, remove all Python versions you have previously installed. You can do that in Control PanelAdd or remove programs.

Visit Python 3.10 on Microsoft Store and install the Python software.

This step is most likely to go wrong. Let’s do a check.

Press the Windows key on your keyboard and type “cmd” to find a program called “Command Prompt”.

Open the Command Prompt App. You should see a black terminal like you are a hacker…

Type “python” and press Enter. You should see you see it prints out Python 3.10. This tells you your Python is installed correctly.

Now you can close the Command Prompt App.

Don’t proceed to the next step until you get Python 3.10 installed correctly.

If you don’t see Python 3.10 running, try

  • Restarting the PC
  • Removing all the previous versions of Python and reinstalling from the Microsoft Store
  • If the one from Microsoft Store doesn’t work for you, remove it and try the one on the Python website.

Step 2: Install git

Git is a code repository management system. You will need it to install and update AUTOMATIC1111.

Go to this page to download the windows version.

Open the installer. Click Install to accept the license and install the software.

git install windows

Follow the instruction to complete the installation.

Step 3: Clone web-ui

This step downloads the Stable Diffusion software (AUTOMATIC1111).

Press the Window key (It should be on the left of the space bar on your keyboard), and a search window should appear. Type cmd.

Click on Command Prompt. The command prompt window would show up.

First, make sure you are in your home folder by typing the following command and then pressing Enter. (Tip: You should be able to use right-click to paste in Command Prompt.)

cd %userprofile%

You should see your prompt shows something like C:\Users\YOUR_USER_NAME>.

Next type the following command and press Enter to clone the AUTOMATIC1111 repository.

git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git

A folder called stable-diffusion-webui should be created in your home directory.

It’s ok to clone the repository in a different folder instead of %userprofile%, as long as you can find the newly created stable-diffusion-webui folder. You will need to change the folder location accordingly in the following steps.

Step 4: Download a model file

Next, go to the newly created folder in File Explorer. Put in

%userprofile%\stable-diffusion-webui

in the address bar and press enter.

Navigate to the folder models and then Stable-diffusion. You should see a file Put Stable Diffusion checkpoints here.txt like below.

Download the Stable Diffusion v1.5 model checkpoint file (download link). Put it in that folder.

Step 5: Run webui

Now in File Explorer, go back to the stable-diffusion-webui folder. That is, go back up two levels or type

%userprofile%\stable-diffusion-webui

again in the address bar.

Find a file called webui-user.bat. Double-click to run and complete the installation.

This last step is going to take a while. When it is done, you will see a message

Running on local URL: http://127.0.0.1:7860

like the one below.

In your web browser, go to the URL

http://127.0.0.1:7860/

You should see the AUTOMATIC1111 webui! Put in a prompt (e.g. “a cat”) and hit Generate to test if Stable Diffusion is running correctly.

When you are done using Stable Diffusion, close the cmd black window to shut down Stable Diffusion.

To rerun Stable Diffusion, you need to double-click the webui-user.bat.

Options

You can speed up Stable Diffusion with the --xformers option. If you have less than 8 GB VRAM on GPU, it is a good idea to turn on the --medvram option to save memory to generate more images at a time.

To enable them, right-click on the file webui-user.bat and select Edit. (You may need to select “Show More Options” first if you use Windows 11).

Replace the line

set COMMANDLINE_ARGS=

With

set COMMANDLINE_ARGS=--xformers --medvram

Save and close the file.

Double-click the webui-user.bat file to run Stable Diffusion.

Additional arguments

Use the argument --gradio-img2img-tool color-sketch to enable the color sketch tool, which could be helpful in img2img.

If you want to use the computer as a server and access the GUI with another computer, use the argument --listen to enable a connection from another computer. You will need to set the firewall appropriately on the server, and this is beyond the scope of this installation guide.

Next Step

That’s it! I hope you will have fun making AI images.

If you are new to Stable Diffusion, check out the Quick Start Guide for some quick tips to use Stable Diffusion.

Head to our beginner’s series to learn Stable Diffusion step by step.

Check out this prompt generator for building high-quality prompts.

RTX 4000 series graphic cards

Good news for you if you use RTX 4070, RTX 4080 or RTX 4090 Nvidia graphic cards. The latest version of AUTOMATIC1111 supports these video card. (with torch 2.0 and cuda 11.8)

I will provide a benchmark speed so that you can make sure your setup is working correctly. The settings are:

  • batch size: 4
  • batch count: 10
  • Image size: 512×512
  • Sampling steps: 20
  • Sampling method: Euler a
  • Model: SD v1.5

Using a batch size of 1 is not recommended, as the measured speed is likely to be highly dependent on other components on your system.

You should see the speed of generating each image. Pick a stable value, usually in the middle like the 5th batch. The speed is in it/s (iterations per second).

You should get about 10 its/s on RTX 4090. (Note that this is 4 images per iteration) This is the max speed you can get nowadays.

You can use one of the following speed-up parameters.

Option 1:

--xformers

Option 2:

--opt-sdp-no-mem-attention --no-half-vae --opt-channelslast

Option 2 is slightly faster, but test them out to see what works best for you.

Updating AUTOMATIC1111

By default, your copy of AUTOMATIC1111 won’t be automatically updated. Given how fast things are moving, you will likely need to update your copy at some point to use the latest and the coolest.

There are two options for updating it. (1) Updating every time when you run it, and (2) Updating only when needed.

Updating every time you run

To update whenever you run webui, edit the file webui-user.bat. Add “git pull” before the line calling webui.bat. The file should look something like

@echo off

set PYTHON=
set GIT=
set VENV_DIR=
set COMMANDLINE_ARGS=--xformers --medvram
git pull
call webui.bat

From now on, webui will update itself every time it starts.

Updating as needed

It may not be a good idea to use the latest version because something could be broken. Updating periodically or only if you need a new feature is a more prudent approach.

To update the webui, open Command Prompt (cmd) and go to webui’s directory using the command below. (You will need to change %userprofile% if you installed it somewhere else.)

cd %userprofile%\stable-diffusion-webui

And run the command

git pull

Resetting webui

If git pull shows an error, it is usually because you have accidentally changed some files. You can reset the webui folder with the following two commands.

cd %userprofile%\stable-diffusion-webui
git checkout -f master

And then run git pull again.

git pull

Note that all files will be reset. You will need to make changes to webui-user.bat again.

Reverting back to a previous version

Sometimes the latest version of webui is broken, and you don’t want to use it. You can revert back to a previous version by following the instructions below.

Step 1: Go to this page to view previous versions. Each row is a previous version.

Step 2: Pick a previous version you want to revert back to. You can look at the date and comment to make a judgment.

Step 3: Press the copy button to copy the hash code of the version.

Step 4: In the command prompt, run the following commands. The hash code (highlighted below) is just an example. You will paste the one you just copied.

cd %userprofile%\stable-diffusion-webui
git checkout 076d624a297532d6e4abebe5807fd7c7504d7a73

If you see errors, reset the webui (see the previous section) and retry.

After checking out the previous code, delete the venv folder and restart WebUI.

Frequently Asked Questions

AUTOMATIC1111 does not start after updating.

Delete the venv folder and restart AUTOMATIC1111.

If it still doesn’t work, delete both the venv and the repositories folders and restart.

If it still doesn’t work and you have recently installed an extension, delete the folder of that extension in the extensions folder. Delete the venv folder and restart.

Does it work on AMD GPU?

No, you have to have an NVIDIA GPU.

What Python version should I use?

Python 3.10.6. Later versions of 3.10 work fine. But don’t use 3.11 or later.

How to resolve NaN errors when generating images?

Add --no-half argument to webui-user.bat (See Adding arguments)

How to resolve out-of-memory errors?

Use --lowvram instead of --medvram argument in webui-user.bat (See Adding arguments)

For optimizing memory usage for SDXL models:

  • Nvidia (12GB+) --xformers
  • Nvidia (8GB) --medvram-sdxl --xformers
  • Nvidia (4GB) --lowvram --xformers

See this article for more details.

Python doesn’t work correctly.

Try removing the previously installed Python using Add or remove programs.

There are two options for installing Python listed. Try the other one if the one you used didn’t work.

Is there an easier way to install AUTOMATIC1111?

The above is the official install instructions. Two alternatives:

I tried everything, but it still does not work.

You can use Google Colab to run AUTOMATIC1111. This is what I use. The notebook launches AUTOMATIC1111 with one mouse click.

Or Use AUTOMATIC1111 online.

Avatar

By Andrew

Andrew is an experienced engineer with a specialization in Machine Learning and Artificial Intelligence. He is passionate about programming, art, photography, and education. He has a Ph.D. in engineering.

426 comments

  1. For whatever reason CMD can not download the torch-2.0.1%2Bcu118-cp310-cp310-win_amd64.whl file, I’m downloading it myself and wanted to know where exactly I should put it?

    1. Hey, I have the same issue. I would like to know where you downloaded the torch-2.0.1%2Bcu118-cp310-cp310-win_amd64.whl file yourself. Please drop a link.

  2. Just wanted to say thanks for the guide. Followed your instructions step by step and SD has been running perfect for the last four months. I am running SD on win 10 Ryzen 5 3600 32gig ram and RTX 3060 12gig. I am sure this is not the fastest build to run this on but have had no issues and it processes the outputs at a decent rate. I do have one question for OP or others can anyone suggest alternative sites to find models and loras outside civitai or HF. From an old man who started out with a Vic-20 and is trying to keep up with new tech these days thanks so much for this well written and easy to follow guide.

  3. Hi Andrew,

    When I double click on webui-user.bat it returns me error as below:
    venv “C:\Users\willi\stable-diffusion-webui\venv\Scripts\Python.exe”
    Python 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
    Version: v1.7.0
    Commit hash: cf2772fab0af5573da775e7437e6acdca424f26e
    Traceback (most recent call last):
    File “C:\Users\willi\stable-diffusion-webui\launch.py”, line 48, in
    main()
    File “C:\Users\willi\stable-diffusion-webui\launch.py”, line 39, in main
    prepare_environment()
    File “C:\Users\willi\stable-diffusion-webui\modules\launch_utils.py”, line 384, in prepare_environment
    raise RuntimeError(
    RuntimeError: Torch is not able to use GPU; add –skip-torch-cuda-test to COMMANDLINE_ARGS variable to disable this check

    Would you please advise?
    Thanks a lot
    William

  4. Thanks Andrew! I accidentally installed it on 3.11…runs fine most of the time, and with some modules, like Controlnet and Animatediff. BUT animatediff likes to sometimes tell me it doesn’t which of the two cues devices to use. I assume I have one…..
    After reading this, I’ll go back to 3.10.x

    Thanks for the awesome setup guide with images

  5. Well, that was short:
    import importlib.metadata
    ModuleNotFoundError: No module named ‘importlib.metadata’
    —————-
    Could you update the webui.bat script to make it install all the python dependencies? Getting them one by one is a pain in the ass.

    1. First, I dont write the software. I merely wrote the installation guide.

      normally it will install all packages. Check what python you are using. have to be 3.10.x

    2. Just to confirm, did you generate the venv before running install.py? If not, your virtual environment is missing a ton of stuff. I ran into that today tbh lol

  6. There’s a typo in your screenshot under Options (–xformers missing the s on the end)

    I also had trouble with a new install:
    AssertionError: An object named ‘ResNetArcFace’ was already registered in ‘arch’ registry!

    fixed by deleting folders
    basicsr and gfpgan from
    stable-diffusion-webui\venv\Lib\site-packages\

    then re-running webui-user.bat

  7. Installing torch and torchvision
    Looking in indexes: https://pypi.org/simple, https://download.pytorch.org/whl/cu118
    WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(‘: Failed to establish a new connection: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions’)’: /simple/torch/

    Any pointers?

  8. As of late 2023-early 2024, Automatic1111 will work with an AMD GPU, but you have to be running Linux, and the process is non-trivial. AMD has created a software translation layer called ROCm that sits underneath Pytorch and allows an AMD GPU’s shaders to pretend to be CUDA cores. The Linux version is still very, very new, and there are constant problems with the nightly build breaking when the user installs a newer version of Python, etc., etc. I am optimistic that it will get better. For now it’s maybe not ready for prime time. A ROCm implementation for Windows is still a work in progress. Intel and Microsoft have created a package they call DirectML that has some conceptual similarities to ROCm, which at least theoretically allows Stable Diffusion to run on an AMD GPU. Currently DirectML is little, if at all, faster than running it on the CPU.

    I have a different problem. I have Windows and an nVidia GPU, but A1111 won’t complete the installation. It gives error messages about cv2 and missing DLL files. I am running a de-bloated and de-crapified Windows 10 N installation. Apparently some part of Python for Windows is dependent on DLL files only found in the more vanilla versions of Windows 10. These files are not available from MS. I am annoyed. I had A1111 working with Linux, sort of, until I tried to install Dreambooth. Then everything stopped working and I got Python error messages I’m still trying to figure out. I wouldn’t have touched Dreambooth but Kohya_ss wouldn’t install either, dying in a convulsion of Python errors about dependencies and versions. I am annoyed.

  9. Hi Andrew,
    Thanks for the article. I am having issues with getting the ReActor extension to appear. I originally had the Roop extension installed before ReActor extension installation. The ReActor extension does not appear for me at all, even with the Roop extension ‘unticked,’ as well as applying and restarting UI.

    I also deleted the Roop folder (C:\Users\KainPC\stable-diffusion-webui\extensions), have deleted the VENV folder entirely, and made sure there is only one folder for insightface, at C:\Users\KainPC\stable-diffusion-webui\models\insightface with the inswapper_128.onnx file inside.

    I’m stuck in trying to get ReActor to work without having to do an entire uninstall and reinstall. Please could you assist?

    Kind regards,
    Kain

    1. Opening an issue on the ReActor repos may get a better help… But I will try to help since you asked.

      My experience with installing ReActor was that it works out of the box. But its possible that there’s a conflict with another extension. You can look for an error message during startup.

  10. Já fiz todas as recomendações aqui do site para a correção do erro abaixo, porem não tive sucesso. Alguém pode me ajudar de outra forma?

    Creating venv in directory C:\Users\xxxxxritório\stable-diffusion-webui\venv using python “C:\Users\xxxxxrit¾rio\AppData\Local\Programs\Python\Python310\python.exe”
    Unable to create venv in directory “C:\Users\xxxxxritório\stable-diffusion-webui\venv”

    exit code: 3

    stderr:
    O sistema não pode encontrar o caminho especificado.

    Launch unsuccessful. Exiting.
    Pressione qualquer tecla para continuar. . .

    1. It could be that your user name “xxxxxrit¾rio” has special characters. Try installing in a local that you can create files but the path doesn’t have special characters.

  11. Hi Andrew, great guide, thank you! When running the CMD to obtain the git clone, I get this:
    fatal: destination path ‘stable-diffusion-webui’ already exists and is not an empty directory.
    The trouble is, I can’t trace that instance of it. Not even in %AppData%. I did have an earlier version but so far as I can see, it’s completely gone. Where could it be tucked away? Any clues would be useful for me to work on. Thanks!

  12. Creating venv in directory C:\Users\asus\uday\stable-diffusion-webui\venv using python “C:\Users\asus\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\python.exe”
    Unable to create venv in directory “C:\Users\asus\uday\stable-diffusion-webui\venv”

    exit code: 1

    stderr:
    Error: Command ‘[‘C:\\Users\\asus\\uday\\stable-diffusion-webui\\venv\\Scripts\\python.exe’, ‘-m’, ‘ensurepip’, ‘–upgrade’, ‘–default-pip’]’ returned non-zero exit status 1.

    Launch unsuccessful. Exiting.
    Press any key to continue . . .

    can someone please help

  13. Can anyone help me, thank you very much.
    -1
    here is my problem, I download a model from civitai and choose it as checkpoit but went i load cmd there is a problem and i cant generate any image, i deleted the model and replace it with another and everything is normal. Can someone have me with this error, thank you very much

    RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu and cuda:0! (when checking argument for argument index in method wrapper_CUDA__index_select)

    i deleted the model and replace it with another and everything is normal.

  14. Thank you very much for this useful guide, and also for helping users trouble-shoot in the comments. I am not very tech-oriented, but I was able to install and use SD with this page and your helpful comments.

    Thank you so much! =)

  15. Hello there.
    i did everything as you said and i recieve this error :
    RuntimeError: CUDA error: no kernel image is available for execution on the device CUDA kernel errors might be asynchronously reported at some other API call, so the stacktrace below might be incorrect. For debugging consider passing CUDA_LAUNCH_BLOCKING=1. Compile with `TORCH_USE_CUDA_DSA` to enable device-side assertions.
    I deleted venv folder and ran webui.bat again.still this error occures.can you help me please?

  16. Can someone help?

    NansException: A tensor with all NaNs was produced in Unet. This could be either because there’s not enough precision to represent the picture, or because your video card does not support half type. Try setting the “Upcast cross attention layer to float32” option in Settings > Stable Diffusion or using the –no-half commandline argument to fix this. Use –disable-nan-check commandline argument to disable this check.

  17. Yo, why only python 3.10, and not newer? Whats wrong with next versions, anddd i lost some new function with 3.10? Thank youuu

  18. Hello!

    There are errors in arguments in FAQ:

    How to resolve out-of-memory errors?

    Use –low-vram instead of –med-vram argument in webui-user.bat (See Adding arguments)

    Correct arguments: –lowvram / –medvram