Skip to content

Instantly share code, notes, and snippets.

@txoof
Last active June 5, 2025 07:28
Show Gist options
  • Save txoof/675e72d43f1bfbade04fdcec99ff4085 to your computer and use it in GitHub Desktop.
Save txoof/675e72d43f1bfbade04fdcec99ff4085 to your computer and use it in GitHub Desktop.
Setup python with tkinter under homebrew

Setting up Python with TK on Mac OS

From scratch:

Uninstall homebrew if needed:

Remove homebrew from Catalina-Mojave:

https://osxdaily.com/2018/08/12/how-uninstall-homebrew-mac/

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

Install Homebrew

https://brew.sh/

Install PyEnv

Set up PyEnv

https://opensource.com/article/19/5/python-3-default-mac#what-to-do

  • brew install pyenv

SetUp for TK Inter

https://stackoverflow.com/questions/60469202/unable-to-install-tkinter-with-pyenv-pythons-on-macos

  • brew install tcl-tk
  • brew info tcl-tk
env \
  PATH="$(brew --prefix tcl-tk)/bin:$PATH" \
  LDFLAGS="-L$(brew --prefix tcl-tk)/lib" \
  CPPFLAGS="-I$(brew --prefix tcl-tk)/include" \
  PKG_CONFIG_PATH="$(brew --prefix tcl-tk)/lib/pkgconfig" \
  CFLAGS="-I$(brew --prefix tcl-tk)/include" \
  PYTHON_CONFIGURE_OPTS="--enable-framework --with-tcltk-includes='-I$(brew --prefix tcl-tk)/include' --with-tcltk-libs='-L$(brew --prefix tcl-tk)/lib -ltcl8.6 -ltk8.6' " \
  pyenv install 3.8.5

if pyenv refuses to build or stalls out using the above method skip using env try this:

env \
  PATH="$(brew --prefix tcl-tk)/bin:$PATH" \
  LDFLAGS="-L$(brew --prefix tcl-tk)/lib" \
  CPPFLAGS="-I$(brew --prefix tcl-tk)/include" \
  PKG_CONFIG_PATH="$(brew --prefix tcl-tk)/lib/pkgconfig" \
  CFLAGS="-I$(brew --prefix tcl-tk)/include" \
  PYTHON_CONFIGURE_OPTS="--enable-framework --with-tcltk-includes='-I$(brew --prefix tcl-tk)/include' --with-tcltk-libs='-L$(brew --prefix tcl-tk)/lib -ltcl8.6 -ltk8.6' " \
PYENV_DEBUG=1 \
pyenv install -v 3.8.5```
  • pyenv global 3.8.5 -- set default version
  • pip install pipenv jupyter
  • it's possible that only 3.7 will work with pyinstaller -onefile
@addition-tg
Copy link

addition-tg commented Feb 20, 2025

Thank you! I have been trying to get turtle to work on my mac, and this helped me get there. I shared the gist with others over on StackOverflow with people in similar situations.

@txoof
Copy link
Author

txoof commented Feb 20, 2025

I'm so glad it could help! I often feel like Cueball in the Wisdom of the Ancients comic.
To quote Randal Munroe: All long help threads should have a sticky globally-editable post at the top saying 'DEAR PEOPLE FROM THE FUTURE: Here's what we've figured out so far ...'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment