matplotlib 错误 - 没有名为 tkinter 的模块

新手上路,请多包涵

我尝试在 Windows 10 上通过 Pycharm IDE 使用 matplotlib 包。当我运行此代码时:

 from matplotlib import pyplot

我收到以下错误:

 ImportError: No module named 'tkinter'

我知道在 python 2.x 中它被称为 Tkinter,但这不是问题——我刚刚安装了一个全新的 python 3.5.1。

编辑:此外,我还尝试导入 ‘tkinter’ 和 ‘Tkinter’ - 这些都不起作用(都返回了我提到的错误消息)。

原文由 noamgot 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.1k
2 个回答

对于 Linux

基于 Debian 的发行版:

 sudo apt-get install python3-tk

基于 RPM 的发行版:

 sudo yum install python3-tkinter

对于窗户:

对于 Windows,我认为问题在于您没有安装完整的 Python 包。因为 Tkinter 应该随 Python 一起提供。请参阅: http ://www.tkdocs.com/tutorial/install.html。 Anaconda 或 ActiveState 公司可以找到适用于 Windows 的良好 python 发行版。

测试python模块

python -c "import tkinter"

ps 我建议安装 ipython ,它也提供了强大的 shell 和必要的包。

原文由 knh170 发布,翻译遵循 CC BY-SA 4.0 许可协议

您可以使用

import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt

如果您根本不想使用 tkinter

如果使用笔记本,也不要忘记在笔记本顶部使用 %matplotlib inline

编辑: agg 是一个不同的后端,就像 tkinter 对于 matplotlib。

原文由 markroxor 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题