Written by Manabu Bannai

Beginner's Guide: Stable Diffusion on your MacBook (M1 / M2)

I will explain how to install Stable Diffusion on your MacBook.

5 Steps to Install Stable Diffusion:

In addition to the above, I will explain how to solve the common error. Before starting the tutorial, the Prerequisites are as follows:

Mac Hardware Requirements:

*You can run Stable Diffusion with 8GB of RAM, but extremely slow.

Before beginning, I want to thank the article: Run Stable Diffusion on your M1 Mac’s GPU. I made my article by adding some information to that one.

STEP1. Install Python V3

Install the latest version of Python:

$ python3 -V
Python 3.10.6

You need Python 3.10 or higher. If not, proceed the STEP2.

STEP2. Install Homebrew

If you have Python 3.10 or higher, you can skip STEP2. You can install the latest version of Python to do so:

$ brew update
$ brew install python

If you are new to brew, install it here: Install Homebrew. After installing, you can check the version to do so:

$ python3 -V
Python 3.10.6

You can see that Python has been installed on your MacBook.

STEP3. Clone Repository

You can clone the fork of Stable Diffusion to do so:

$ git clone -b apple-silicon-mps-support https://github.com/bfirsh/stable-diffusion.git
$ cd stable-diffusion
$ mkdir -p models/ldm/stable-diffusion-v1/

No need to explain, right? Let's move on to the next step.

STEP4. Set up Virtualenv

You need the followings to enable your virtualenv:

$ python3 -m pip install virtualenv
$ python3 -m virtualenv venv

To enable the virtualenv, run the command below:

$ source venv/bin/activate

*FYI: You need to run the command to use Stable Diffusion whenever you want. This is the activation command.

Then, run the below command to install the dependencies:

$ pip3 install -r requirements.txt

If you face an error like Failed building wheel for onnx, the following command will probably fix the issue:

$ brew install cmake protobuf rust

Okay. The preparation is almost finished. The next is the last step.

STEP5. Run Stable Diffusion

You need the weights, the parameter within a neural network, to run Stable Diffusion on your MacBook.

So please go to Hugging Face and then click on the Access repository.

After that. You can download the file: sd-v1-4.ckpt. Rename it and move to models/ldm/stable-diffusion-v1/model.ckpt

Finally,,, Run Stable Diffusion!

Run it using the command like so:

$ python3 scripts/txt2img.py --n_samples 1 --n_iter 1 --plms --prompt "fake version of Doraemon"

The result is the following (Input: fake version of Doraemon):

You can find your images in outputs/txt2img-samples.

Okay. That's it for the explanation. The following sentences answer the question of common errors.

Error: No module named ‘cv2’

You may face the following error:

File "/Users/stable-diffusion/scripts/txt2img.py", line 2, in
import cv2
ModuleNotFoundError: No module named 'cv2'

The solutions are like so (Try two command):

I can solve the error using $ python3 scripts/txt2img.py. I think this is a very common issue to run Stable Diffusion on your MacBook.

Error: FileNotFoundError: ‘model.ckpt’

You may face the following error:

FileNotFoundError: [Errno 2] No such file or directory: 'models/ldm/stable-diffusion-v1/model.ckpt'

It's easy to fix to change the file name like so:

Okay. That's it for the answer to common errors.

Still having Errors...? The Solution is Here

You may face the difficulty of googling the information related to Stable Diffusion because it is a very new technology.

The Solution: Search in the Discord Community

I highly recommend Replicate Discord Community, a free group for those with an interest in AI tools. There are many people asking about Stable Diffusion, so you can do the same.

But in my opinion, you don't need to ask your questions. Instead, simply search the keywords in the Discord Community, which will probably solve your issue.

Also, StableDiffusion on Reddit is a great place for learning. If you want to learn new technology, Discord and Reddit are better place for searching than Google.

That's it. Thanks for reading. Please enjoy Stable Diffusion :)