How to install Stable Diffusion on a PC

Today there are many web applications that allow us to create images using the Stable Diffusion Artificial Intelligence model. These online applications are very good, but the bad thing is that at some point, if we want to use them on a recurring basis, it is necessary to pay.

That means that we can install it on our PC and use it for free to create as many images as we want. Not bad!
If you’re interested in learning about stable diffusion, you’ve come to the right place, because in this article we will cover everything from computer requirements, the installation process, to basic commands.

Requirements to be able to run Stable Diffusion on a PC

Stable Diffusion is a machine learning model that requires some hardware power, and therefore, you will not be able to install it on any mid-range or low-end PC. The minimum requirements are as follows:

  • A GPU with at least 6GB of VRAM.
  • Around 100GB of free disk storage space.
  • A PC running Windows 8, Windows 10, Windows 11, Linux, or macOS.

Another detail to take into account is that the standard version of Stable Diffusion does not have a graphical interface , which means that we will have to use commands to generate the images. Quiet! As we will see a little further down, it is really easy to use.

Note: If your PC does not meet the minimum requirements, remember that you can also try the online demo of Stable Diffusion 2.1 for free to generate images from the browser.

How to install Stable Diffusion on your desktop PC

If your team meets the minimum requirements, it’s time to get down to business.

  • Download and install the Git application. This is a developer tool that allows you to manage different software versions. You can download the installer from the official Git page (64-bit version for Windows).
  • When installing Git, leave all the options as they are by default. Especially the section where the option “Git from the command line and also from 3rd-party software.
  • Now it’s time to install the Miniconda3 application. It is a tool that allows you to manage all the libraries necessary to run Stable Diffusion. You can download Miniconda3 (64-bit version for Windows) from its official website .
  • When installing the application, select the option “ Install for: All Users”. Leave the rest of the options as they are.
  • Next, download the most recent Stable Diffusion checkpoint from its official website. Currently the most recent version is 1.4. Click on it and in the next window click on the checkpoint “ sd-v1-4-ckpt ” to download the software from GitHub (it is about 4GB in size).
  • Now, download the Stable Diffusion software from its GitHub repository. Click on the green “Code” button and click on “ Download ZIP ”. The file only weighs about 45MB.

At this point, now that we have all the software in our hands, it is time to prepare a folder where we will store all the Stable Diffusion files.

  • Open the Windows search engine, type “miniconda3” and open the application.
  • Type the following commands one by one:
    • cd C:/
    • mkdir stable-diffusion
    • cd stable diffusion
  • Next, open Windows File Explorer and unzip the Stable Diffusion ZIP file that you downloaded from GitHub ( stable-diffusion-main.zip). Copy that folder and paste it into the new “stable-diffusion” folder we just created in the root of C.
  • Go back to the miniconda terminal window and run the following commands one by one. This is a process that can take several minutes, so don’t close the window:
    • cd C:\stable-diffusion\stable-diffusion-main
    • conda env create -f environment.yaml
    • conda activate ldm
    • mkdir models\ldm\stable-diffusion-v1
  • Finally, open the file explorer, go to the folder “C:\stable-diffusion\stable-diffusion-main\models\ldm\stable-diffusion-v1” and paste the 4GB checkpoint file ( sd- v1-4.ckpt)that you downloaded a while ago.
  • To finish, right click on the “sd-v1-4.ckpt” file and rename it “model.ckpt”.

We already have Stable Diffusion installed and ready to start generating images for free on our PC. But how does it work?

How to use Stable Diffusion via commands

To generate images with Stable Diffusion the process to follow is quite simple. Of course, we will do everything through commands from a Miniconda3 terminal window.

  • Open the Windows search engine and run the Miniconda3 application.
  • Run the command “ conda activate ldm” (without quotes).
  • Change the directory to “C:\stable-diffusion\stable-diffusion-main”. To do this, run the command “ cd C:\stable-diffusion\stable-diffusion-main” (without quotes).

Now we have everything ready to ask Stable Diffusion to create an image from the text that we tell it (keep in mind that it must be in English). To do this, run the following command:

python scripts/txt2img.py –prompt “a photo of cat flying out to space as an astronaut, digital art” –plms –n_iter 4 –n_samples 1

In this order we have asked you to generate 4 images (512×512 pixels) of “a cat flying in space like an astronaut”. Replace the section between quotes in the command and enter the desired image request.

AI-generated images are automatically saved in the “C:\stable-diffusion\stable-diffusion-main\outputs\txt2img-samples\samples” folder.

known bugs

The first time you run the txt2img.py script, you may get the error “ cannot import name ‘SAFE_WEIGHTS_NAME’ from ‘transformers.utils ‘”. To fix it, run the following command in the Miniconda3 terminal window.

  • pip install diffusers==0.12.1

With this command, what we will do is downgrade the diffuser libraries to version 0.12.1, which is a version where it is confirmed that Stable Diffusion works correctly.

I hope this tutorial has been helpful to you. See you in the next post!

by Abdullah Sam
I’m a teacher, researcher and writer. I write about study subjects to improve the learning of college and university students. I write top Quality study notes Mostly, Tech, Games, Education, And Solutions/Tips and Tricks. I am a person who helps students to acquire knowledge, competence or virtue.

Leave a Comment