当前位置:   article > 正文

手机python没有tk模块_无法在安装pyenv的情况下运行IDLE:`可能未为Tk配置Python``ModuleNotFoundError:没有名为_tkinter的模块'...

手机版python3没有tkinter怎么安装

I recently spent couple hours making tkinter and IDLE work on my pyenv Python installation (macOS).

Why you are here?

You manage Python versions with pyenv on macOS and

( You want IDLE - the development environment for Python - work on your macOS

or you want tkinter module work )

What's wrong?

You get one of the following errors:

Python may not be configured for Tk on import tkinter

import _tkinter # If this fails your Python may not be configured for Tk

RuntimeError: tk.h version (8.6) doesn't match libtk.a version (8.5)

ModuleNotFoundError: No module named '_tkinter'

解决方案

Here is step by step guide to make IDLE and tkinter work:

install tcl-tk with Homebrew. In shell run brew install tcl-tk

in shell run echo 'export PATH="/usr/local/opt/tcl-tk/bin:$PATH"' >> ~/.zshrc

reload shell by quitting Terminal app or run source ~/.zshrc

after reloaded check that tck-tk is in $PATH. Run echo $PATH | grep --color=auto tcl-tk. As the result you should see your $PATH contents with tcl-tk highlighted

now we run three commands from Homebrew's output from step #1

in shell run export LDFLAGS="-L/usr/local/opt/tcl-tk/lib"

in shell run export CPPFLAGS="-I/usr/local/opt/tcl-tk/include"

in shell run export PKG_CONFIG_PATH="/usr/local/opt/tcl-tk/lib/pkgconfig"

if you have your Python version already installed with pyenv then uninstall it with pyenv uninstall . E.g. pyenv uninstall 3.8.2

set environment variable that will be used by python-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 actual

finally install Python with pyenv with pyenv install . E.g. pyenv install 3.8.2

Test

in shell run pyenv global

now check IDLE. In shell run idle. You should see IDLE window without any warnings and "text printed in red".

now check 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:

macOS Catalina

zsh (included in macOS Catalina) = "shell" above

Homebrew (installed with instructions from Homebrew official website)

pyenv (installed with Homebrew and PATH updated according to pyenv official readme from GitHub)

Python 3.8.x - 3.9.x (installed with pyenv install command)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/213660
推荐阅读
相关标签
  

闽ICP备14008679号