Jupyter 与 IPython:Matplotlib - 没有名为 Tkinter 的模块

斯蒂芬·雅各布

我在名为 OpenQuake 的程序中使用 Python 3.5。当我执行以下行时,出现导入错误“No module name 'tkinter'”。

import matplotlib.pyplot as plt

我安装了 jupyter 并执行了相同的操作,它工作正常。以下是快照。在此处输入图片说明我使用 IPython(我相信它与 jupyter 一起提供)重新检查以使用相同的回溯获得完全相同的原始错误。以下是回溯。

Traceback (most recent call last):
  File "<ipython-input-22-964337a9f103>", line 2, in <module>
    import matplotlib.pyplot as plt
  File "C:\Program Files\OpenQuake Engine\lib\site-packages\matplotlib\pyplot.py", line 114, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "C:\Program Files\OpenQuake Engine\lib\site-packages\matplotlib\backends\__init__.py", line 32, in pylab_setup
    globals(),locals(),[backend_name],0)
  File "C:\Program Files\OpenQuake Engine\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 6, in <module>
    from matplotlib.externals.six.moves import tkinter as Tk
  File "C:\Program Files\OpenQuake Engine\lib\site-packages\matplotlib\externals\six.py", line 90, in __get__
    result = self._resolve()
  File "C:\Program Files\OpenQuake Engine\lib\site-packages\matplotlib\externals\six.py", line 113, in _resolve
    return _import_module(self.mod)
  File "C:\Program Files\OpenQuake Engine\lib\site-packages\matplotlib\externals\six.py", line 80, in _import_module
    __import__(name)
ImportError: No module named 'tkinter'

在这两种情况下,引用的 matplotlib 模块是相同的。

总结一下:

  1. 上面的代码片段在使用 Python 和 IPython 时会出现导入错误。
  2. 代码片段在 Jupyter 中成功执行。

有人可以解释为什么会这样吗?

迈克·穆勒

matplotlib 使用不同的后端。在 Jupyter 中,它通常使用inlinenotebook另一方面,IPython 默认使用 TK 后端 ( backend_tkagg.py),因此尝试导入tkinter未安装的 。Jupyter 不需要这个后端,因此不会尝试导入它。

Jupyter 在浏览器中显示绘图结果,但 IPython 在终端上运行,需要一个 GUI 库,例如 TKinter 来显示。这使得需要不同的后弯。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Matplotlib,Jupyter Notebook:ImportError:没有名为Tkinter的模块

OSX中的jupyter内核:没有名为IPython的模块

matplotlib-ImportError:没有名为_tkinter的模块

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

ImportError:没有名为“ Tkinter”的模块

Predix:没有名为 _tkinter 的模块

ImportError:没有名为tkinter的模块

jupyter笔记本导入错误:没有名为“ matplotlib”的模块

ModuleNotFoundError:没有名为“ matplotlib”的模块-在Heroku上部署Jupyter项目的问题

ModuleNotFoundError:没有名为“ Ipython”的模块

ImportError:没有名为IPython的模块

ModuleNotFoundError:没有名为“ matplotlib”的模块

ImportError:没有名为“ matplotlib”的模块

from Tkinter import * ImportError: 没有名为“Tkinter”的模块

Python/Tkinter:ModuleNotFoundError:没有名为“_tkinter”的模块

ModuleNotFoundError:Jupyter Notebook中没有名为“ tensorflow”的模块

Jupyter Notebook中没有名为'graphviz'的模块

没有名为graphframes的模块Jupyter Notebook

Jupyter Notebook ImportError:没有名为枚举的模块

Jupyter pyspark:没有名为pyspark的模块

ModuleNotFoundError:jupyter中没有名为“ pymysql”的模块

在Jupyter Notebook ModuleNotFoundError中:没有名为'plotly'的模块

Jupyter:安装后没有名为“ imblearn”的模块

ImportError:没有名为“ jupyter_client”的模块

ModuleNotFoundError:没有名为“pandas”的模块 - Jupyter

jupyter ModuleNotFoundError:没有名为 Tensorflow 或 keras 的模块

ipython console2没有名为Ipython的模块

ipython iptest ImportError(没有名为ipython的模块)

cx_Freeze 没有名为“Tkinter”的模块