【发布时间】:2021-07-22 21:48:33
【问题描述】:
我一直在尝试将 Tkinter 导入我的程序,但我不断收到错误消息:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/homebrew/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/tkinter/__init__.py", line 37, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
当我尝试python3 -m tkinter:
File "/opt/homebrew/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 188, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/opt/homebrew/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 147, in _get_module_details
return _get_module_details(pkg_main_name, error)
File "/opt/homebrew/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 111, in _get_module_details
__import__(pkg_name)
File "/opt/homebrew/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/tkinter/__init__.py", line 37, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
我尝试使用 pip/python 安装 Tkinter,但它不起作用。以前它可以工作,但在运行之后
ln -s /opt/homebrew/bin/dot /usr/local/bin/dot
它停止工作了。
【问题讨论】:
-
那台计算机上有图形用户界面吗?还有你是怎么安装python的?
-
tkinter是 stript 语言tcl及其 GUI 模块tk的包装器,您可能必须使用homebrew安装它们 - 但通常应该安装所有需要的 `tkinter元素。