ModuleNotFoundError:macOS 上没有名为“_tkinter”的模块

问题描述

Tkinter 不起作用,它会引发错误

安装

% pip3 install tk

我的代码

#!/usr/bin/env python3

import tkinter as tk

错误

Traceback (most recent call last):
  File "/Users/arghadip/Library/Application Support/CodeRunner/Unsaved/Untitled.py",line 4,in <module>
    import tkinter as tk
  File "/usr/local/Cellar/python@3.9/3.9.5/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 tkinter 可以简单地安装,

brew install python-tk

pip 有时无法在我的 Mac 上成功运行,尤其是在 High Sierra OS 版本中。 mac可以用Brew安装各种软件包。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...