赞
踩
System info:
macOS 10.14.6 (Mojave), tcl-tk 8.6.9, pyenv 1.2.15, and python 3.8.0.
ModuleNotFoundError: No module named '_tkinter'
Install pyenv via homebrew
brew install pyenv
Install tcl-tk via homebrew
brew install tcl-tk
Add environment variables into ~/.zshrc
python pyenv
export PATH="
PATH"
if which pyenv > /dev/null; then
eval "$(pyenv init -)";
fi
pyenv-virtualenv
if which pyenv-virtualenv-init > /dev/null; then
eval "$(pyenv virtualenv-init -)";
fi
tcl-tk
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"
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'"
Install pyenv-virtualenv via homebrew
brew install pyenv-virtualenv
Install python by pyenv (3.8.0 for example)
pyenv install 3.8.0
Restart shell
exec $SHELL
Create a local environment of python 3.8.0 by pyenv:
pyenv local 3.8.0
pyenv version
Test tcl-tk installation with:
python -m tkinter -c 'tkinter._test()'
or simply:
idle
Job done.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。