Skip to content

Instantly share code, notes, and snippets.

@scotthaleen
Last active December 11, 2020 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scotthaleen/445c2a7cd2850355a3c50f77a16448df to your computer and use it in GitHub Desktop.
Save scotthaleen/445c2a7cd2850355a3c50f77a16448df to your computer and use it in GitHub Desktop.

Fix tkinter on osx

import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'

brew install tcl-tk zlib
export PATH="/usr/local/opt/tcl-tk/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/tcl-tk/lib -L/usr/local/opt/zlib/lib"
export CPPFLAGS="-I/usr/local/opt/tcl-tk/include -I/usr/local/opt/zlib/include"
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:/usr/local/opt/tcl-tk/lib/pkgconfig"
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:/usr/local/opt/zlib/lib/pkgconfig"
pyenv uninstall 3.8.2
PYTHON_CONFIGURE_OPTS="--with-tcltk-includes='-I/usr/local/opt/tcl-tk/include' --with-tcltk-libs='-L/usr/local/opt/tcl-tk/lib -ltcl8.6 -ltk8.6'" pyenv install 3.8.2

pyenv shell 3.8.2

python -m tkinter -c "tkinter._test()"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment