If you search for this symptom, you will find some articles in Qiita, but for some reason it didn't work and I made a lot of trial and error, so I made a note.
TL;DR
--If there is no tcl-tk
, enter it with brew install tcl-tk
--If you wrote PYTHON_CONFIGURE_OPTS
and it doesn't improve, check the version of tcl-tk to see if the correct version is written.
-↑ If that doesn't work, try adding --enable-shared
to the end.
Mac Book Pro macOS Catalina 10.15.7
anyenv anyenv 1.1.2-1-g67d402f pyenv 1.2.21
Tkinter, which I see in other articles, doesn't work. I didn't make a note of the terminal log because I thought it could be solved quickly, but it was almost the same as I see in other articles.
Install tcl-tk
with Homebrew
brew install tcl-tk
So, I added various things to the environment variables.
.zshrc
export PATH="/usr/local/opt/tcl-tk/bin:$PATH"
export 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"
In addition, add the option PYTHON_CONFIGURE_OPTS
when building python to .zshrc,
At this time, the version of tcl-tk needs to match the version of the one you put in Homebrew, so check it.
It seems that you can see the version of the package you put in Homebrew with brew info
(I learned today)
brew info tcl-tk
tcl-tk: stable 8.6.10 (bottled) [keg-only]
Tool Command Language
https://www.tcl-lang.org
/usr/local/Cellar/tcl-tk/8.6.10 (3,036 files, 51MB)
Poured from bottle on 2020-11-09 at 10:51:55
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/tcl-tk.rb
License: TCL
==> Dependencies
Required: [email protected] ✔
==> Caveats
tcl-tk is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.
If you need to have tcl-tk first in your PATH run:
echo 'export PATH="/usr/local/opt/tcl-tk/bin:$PATH"' >> ~/.zshrc
For compilers to find tcl-tk you may need to set:
export LDFLAGS="-L/usr/local/opt/tcl-tk/lib"
export CPPFLAGS="-I/usr/local/opt/tcl-tk/include"
For pkg-config to find tcl-tk you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/tcl-tk/lib/pkgconfig"
==> Analytics
install: 8,020 (30 days), 24,799 (90 days), 101,382 (365 days)
install-on-request: 4,416 (30 days), 13,662 (90 days), 53,123 (365 days)
build-error: 0 (30 days)
It seems to be 8.6.10, so in this case, it seems that you should specify tcl8.6
and tk8.6
.
(I took a look)
ls /usr/local/opt/tcl-tk/lib
Tk.icns libtk8.6.dylib tclConfig.sh tdbcmysql1.1.1
Tk.tiff libtkstub8.6.a tcllib1.20 tdbcodbc1.1.1
itcl4.2.0 pkgconfig tcllibc tdbcpostgres1.1.1
itk4.1.0 sqlite3.30.1.2 tclooConfig.sh thread2.8.5
libtcl8.6.dylib tcl8 tcltls1.7.20 tk8.6
libtclstub8.6.a tcl8.6 tdbc1.1.1 tkConfig.sh
So I will add it to .zshrc
.
.zshrc
export 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'"
Let's read the settings again. You can use . ~ / .Zshrc
, source ~ / .zshrc
, or reopen the terminal
in any way you like.
Once that's done, reinstall python. ... Well, since I left it for a long time, the version included was 3.7.4, which is old, so I'm thinking of installing 3.8.5 newly here. (If it goes well, I feel like putting it back in)
pyenv install 3.8.5
python-build: use [email protected] from homebrew
python-build: use readline from homebrew
Downloading Python-3.8.5.tar.xz...
-> https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tar.xz
Installing Python-3.8.5...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Installed Python-3.8.5
Then switch the global version
pyenv global 3.8.5
python -V
Python 3.8.5
Well then.
python -m tkinter -c "tkinter._test()"
(Omitted)
RuntimeError: tk.h version (8.6) doesn't match libtk.a version (8.5)
What?
Everyone says it worked.
A further search on Google revealed that when setting PYTHON_CONFIGURE_OPTS
, adding --enable-shared
also worked opinion. / questions / 60469202 / enable-to-install-tkinter-with-pyenv-pythons-on-macos # comment112082121_61879759) So let's try it.
- export 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'"
+ export 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' --enable-shared"
So, reload .zshrc
again and reinstall python
pyenv uninstall 3.8.5
pyenv: remove /Users/*****/.anyenv/envs/pyenv/versions/3.8.5? [y|N]y
pyenv: 3.8.5 uninstalled
pyenv install 3.8.5
python-build: use [email protected] from homebrew
python-build: use readline from homebrew
Downloading Python-3.8.5.tar.xz...
-> https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tar.xz
Installing Python-3.8.5...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Installed Python-3.8.5
Somehow, it is better to hit idle
and see that there is no error, so I will try that as well.
idle
Looks okay.
Then again.
python -m tkinter -c "tkinter._test()"
It's finally a success. Yay!
If you can't use tkinter with the well-known method, you may want to add --enable-shared
to your build options.
Recommended Posts