Last active
June 2, 2020 12:22
-
-
Save weaming/cfae1d80928ced4ed57ef9b5342f71b3 to your computer and use it in GitHub Desktop.
Install python with tk supported via pyenv on macOS.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/bash | |
# https://github.com/pyenv/pyenv/issues/1375#issuecomment-524280004 | |
# NOTE: following steps does work on my macOS 10.15.4, pyenv 1.2.18 :( | |
# Error example: | |
# ERROR: invalid Python executable: /Users/weaming/.pyenv/versions/3.8.2/bin/python3.8 | |
# The python-build could not find proper executable of Python after successful build. | |
# Finally solution: download .pkg installer from https://www.python.org/downloads/release/python-382/ | |
# it includes its own private version of Tcl/Tk 8.6. It does not use any system-supplied or third-party supplied versions of Tcl/Tk. | |
brew update | |
brew upgrade pyenv | |
brew install tcl-tk | |
# replace text in $(which python-build) | |
# $CONFIGURE_OPTS ${!PACKAGE_CONFIGURE_OPTS} "${!PACKAGE_CONFIGURE_OPTS_ARRAY}" || return 1 | |
# with | |
# $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' ${!PACKAGE_CONFIGURE_OPTS} "${!PACKAGE_CONFIGURE_OPTS_ARRAY}" || return 1 | |
pyenv uninstall 3.8.2 | |
# provide executable `python` to `python-build`: or else will raise error "python-build could not find proper executable of Python after successful build" | |
pyenv global system | |
# How to support PyInstaller: https://github.com/pyinstaller/pyinstaller/wiki/FAQ#mac-os-x | |
# but `--enable-shared` did not work, it's using tcl-tk version 8.5 which is not the latest 8.6 installed via brew | |
# Using `---enable-framework` works! What is it? See https://stackoverflow.com/a/15057523 | |
PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.8.2 | |
# install XQuartz from https://www.xquartz.org to display X window | |
# test if it works | |
python -m tkinter -c 'tkinter._test()' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment