运行 python 3.9.4 时,我无法导入 tkinter,但降级到 3.8.2 工作正常

Adi*_*arg 7 python tkinter python-3.x python-3.8 python-3.9

我在 macOS Catalina 上运行 tcl 8.6.11,我使用安装了 python3 brew install python3

tclsh
% info patchlevel
8.6.11
Run Code Online (Sandbox Code Playgroud)

当前版本的python 3.9.4

python3 --version 
Python 3.9.4 

>>> import tkinter 
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
Run Code Online (Sandbox Code Playgroud)

降级到 3.8.2

python3 --version 
Python 3.8.2

>>> import tkinter
>>> 
Run Code Online (Sandbox Code Playgroud)

不确定是什么原因造成的,任何见解将不胜感激

小智 3

看起来 tkinter 在 python 3.9 的brew 中被禁用,但在 3.8 中却没有,
它在他们的 github 上有评论

如果您想使用 python 3.9,请尝试python-tk公式。