Skip to content

MacOS Python

Vladimir Mandic edited this page Oct 28, 2024 · 1 revision

MacOS and Python

TL;DR: Installation Instructions

The MacOS operating system requires Python, so it is installed by default. However, if you are going to start using Python on your own, it is likely that you'll want to install new packages, perform package updates, and so on -- which can be a problem for MacOS -- it's important to let the operating system handle its own Python.

Most sources online will tell you to use Homebrew as a package manager for MacOS, so it is a natural conclusion to consider using Homebrew for Python -- and it's common to discover that you already have Python installed through Homebrew as a dependency for something else. However, this isn't the correct solution either -- it's really the same problem as the MacOS problem, but with a coat of paint.

Homebrew's Python is there to support other packages. Importantly, Homebrew deletes old versions of packages after 30 days. So, if you are using, say, python 3.12 for random scripting and other tasks, but need version 3.10 for, say, SD.Next, Homebrew will delete 3.10, since it doesn't know that you need it for something (since you didn't install SD.Next via Homebrew).

The solution is to use another way to manage the Python version(s) that you use on your own. I use asdf, which has a Python plugin, but there are others if you prefer something else.

Sources / Further Reading:

Installation Instructions

  1. If you haven't got Homebrew installed already:
mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip-components 1 -C homebrew

eval "$(homebrew/bin/brew shellenv)"
brew update --force --quiet
chmod -R go-w "$(brew --prefix)/share/zsh"
  1. Install asdf and python build dependencies:
brew install asdf openssl readline sqlite3 xz zlib
  1. Add asdf to .zshrc to use it immediately and persistently:
. $(brew --prefix asdf)/asdf.sh
echo -e "\n. $(brew --prefix asdf)/asdf.sh" >> ~/.zshrc
  1. Add the python asdf plugin:
asdf plugin add python

# for SD.Next
asdf install python 3.10.14

# you may want the latest version too; take note of which version is installed
asdf install python latest
  1. Set the default global version of python. Since you will always want 3.10 for SD.Next, you will want to always specifically use that version. You will probably want to use the command python in most contexts, and python3.10 for version-specific uses.
asdf global python 3.12.2 
# or whatever version you installed
  1. Run SD.Next using python3.10:
export PYTHON=$(which python3.10)
cd /path/to/SD.Next
./webui.sh --debug
Clone this wiki locally