我在我的 Mac 上通过 Homebrew 安装了 Python。
brew install python
之后我检查了我的 Python 版本为 2.7.11,然后我尝试执行
import Tkinter
我收到以下错误消息:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 39, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter
原文由 Daniel Chen 发布,翻译遵循 CC BY-SA 4.0 许可协议
我正在运行 MacOS Big Sur (11.2.3)。
使用 python2,我有
Tkinter
内置。使用python3,它必须手动安装并且非常简单,只需运行:
要在终端中运行 python2,请执行
python file.py
。要在终端中运行 python3,请执行
python3 file.py
。