Skip to content

Instantly share code, notes, and snippets.

@txoof
Last active April 18, 2024 15:59
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment