As a Python engineer, I wanted to be involved in a lot of development in the future, so I decided to start developing Python for the first time, and based on the reference book, I decided to create an application using the tkinter module. But an error occurs and the window does not open ...
Since I've been exposed to Puby and PHP so far, I'm used to facing errors, so I decided to check the details of the errors immediately. The following content was written in a part of the error statement.
If this fails your Python may not be configured for Tk
But IDLE works as expected, but why doesn't it work with a text editor?
In other words, I thought that ** my PC (Mac) does not have Tcl / Tk built-in **.
$ ls -al /usr/bin/wish*
$ which wish
$ echo 'puts $tcl_version;exit 0' | wish
$ echo $PATH
Try this in the terminal and the output result will be below!
ChisakinoMacBook-Pro:~ Chisaki$ ls -al /usr/bin/wish*
lrwxr-xr-x 1 root wheel 7 9 21 2018 /usr/bin/wish -> wish8.5
-r-xr-xr-x 1 root wheel 127 8 18 2018 /usr/bin/wish8.5
ChisakinoMacBook-Pro:~ Chisaki$ which wish
/usr/bin/wish
ChisakinoMacBook-Pro:~ Chisaki$ echo 'puts $tcl_version;exit 0' | wish
8.5
ChisakinoMacBook-Pro:~ Chisaki$ echo $PATH
/Users/Chisaki/.pyenv/shims:/Users/Chisaki/.pyenv/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/Library/Frameworks/Python.framework/Versions/3.8/bin:/Library/Frameworks/Python.framework/Versions/3.8/bin:/Users/Chisaki/.pyenv/shims:/Library/Frameworks/Python.framework/Versions/3.8/bin:/Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/opt/[email protected]/bin:/Users/Chisaki/.rbenv/shims:/usr/local/opt/[email protected]/bin:/usr/local/opt/[email protected]/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
From the output result, I thought about ** uninstalling Python anew so that the latest tcl / tk is installed and installing it again **.
$ pyenv uninstall 3.7.6
$ 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="--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.7.6
$ pyenv global 3.7.6
When I executed these in order from the top, I was able to confirm that it works by calling the tkinter module with a text editor ^ _ ^
Recommended Posts