Skip to content

Installation

soten355 edited this page Dec 7, 2023 · 9 revisions

Installation

Currently, MetalDiffusion can only be installed by building from source.

Build from source

These installation instructions are geared towards use on an Intel Mac.

This program is best utilized within a python virtual environment, making it independent of the python already installed on MacOS.

Required MacOS Version:

Ventura or newer

Programs required

  1. Terminal
  2. Xcode (obtained from the Apple App Store)
  3. Homebrew
  4. Pyenv
  5. Python, minimum version 3.9 (3.11 recommended)
  6. Git

Terminal will be used for all of the following commands:

Install Homebrew, if not already installed

Homebrew is a fundamental tool for Mac and is required for this installation process.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Check if brew installed correctly:

brew -v

If a message like Homebrew 3.5.2 is displayed, then it's been successfully installed.

Install/Update pyenv

pyenv allows you to install Python independently from the Mac's base installation.

brew install pyenv

If pyenv is already installed, then Homebrew will update pyenv

Install Python via pyenv

pyenv install 3.9.0

Set the global Python

Set the global python that the Mac will use to the newly installed, via pyenv, python.

pyenv global 3.9.0

This step will override which version and the location of python the Mac will use, allowing for easier updating and control.

Verify Python Installation

Check if python was installed correctly:

python --version

If installed correctly, Terminal will display something like Python 3.11.0

Install/Update git

git allows you to download this repository (repo)

brew install git

If git is already installed, then Homebrew will update git

Download the MetalDiffusion github repo

Navigate to a folder/directory you want to create your virtual environment in. For example: /Users/MacUser

Download the repo, either by downloading the zip file or by cloning the repo with git:

git clone https://github.com/soten355/MetalDiffusion.git

Start working in the virtual environment

First, navigate to the root folder in the github repo that was just installed. For example:

cd /Users/MacUser/MetalDiffusion/

Create a virtual environment with virtualenv

  1. Create your virtual environment for python:

    python -m venv venv
  2. Activate your virtual environment:

    source venv/bin/activate
  3. Upgrade PIP (python package manager):

    pip install pip --upgrade --no-cache-dir
  4. Install dependencies using the requirements.txt file:

    pip install -r requirements.txt --no-cache-dir
  5. Run the program:

    python dream.py
  6. When finished using Stable Diffusion, deactivate the virtual environment:

    deactivate

Troubleshooting

zsh: command not found: brew

Most likely, bash commands necessary for homebrew were not executed in Terminal. Re-install homebrew and look for the specific bash commands it requires to be entered into Terminal. Those commands will be listed at the end of homebrew's installation.

Here's an example of what that command could look like for an M1 Mac:

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zshrc
source ~/.zshrc

zsh: command not found: python

The most likely reason is that pyenv was not installed properly. After installing pyenv, but before installing python, run this code in terminal:

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
source ~/.zshrc

ModuleNotFoundError: No module name '_lzma'

This error is caused by an incorrect installation of Python through pyenv. Uninstall any python versions from pyenv and run the following code through Homebrew:

brew install openssl readline sqlite3 xz zlib tcl-tk

Now re-install Python through pyenv