Versions of Python installed via pyenv fail to import tkinter:
※ python
Python 3.8.1 (default, Feb 29 2020, 11:45:59)
[Clang 11.0.0 (clang-1100.
Here is step by step guide to make tkinter (and IDLE) work if you use pyenv for Python environments management on macOS:
tcl-tk with Homebrew. In shell run brew install tcl-tkecho 'export PATH="/usr/local/opt/tcl-tk/bin:$PATH"' >> ~/.zshrcTerminal app or run source ~/.zshrctck-tk is in $PATH. Run echo $PATH | grep --color=auto tcl-tk. As the result you should see your $PATH contents with tcl-tk highlightedexport LDFLAGS="-L/usr/local/opt/tcl-tk/lib"export CPPFLAGS="-I/usr/local/opt/tcl-tk/include"export PKG_CONFIG_PATH="/usr/local/opt/tcl-tk/lib/pkgconfig"pyenv then uninstall it with pyenv uninstall . E.g. pyenv uninstall 3.8.2python-build. In shell run 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'"
Note: in future use tck-tk version that actually installed with Homebrew. At the moment of posting 8.6 was the actualpyenv with pyenv install . E.g. pyenv install 3.8.2Test
pyenv global idle. You should see IDLE window without any warnings and "text printed in red".tkinter. In shell run python -m tkinter -c "tkinter._test()". You should see test window like on the image:That's it!
My environment:
check this is something went wrong executing steps above:
zsh (included in macOS Catalina) = "shell" abovepyenv (installed with Homebrew and PATH updated according to pyenv official readme from GitHub)3.8.x - 3.9.x (installed with pyenv install command)