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

2024-04-24 10:44:35 发布

您现在位置:Python中文网/ 问答频道 /正文

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

from matplotlib import pyplot

我得到以下错误:

ImportError: No module named 'tkinter'

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

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


Tags: no代码fromimportmatplotlibtkinterwindows错误
3条回答

在Centos上,包名和命令是不同的。你需要:

sudo yum install tkinter

来解决这个问题。

你可以用

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

如果你根本不想使用tkinter

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

编辑:agg与matplotlib的tkinter不同。

sudo apt-get install python3-tk

那么

>> import tkinter # all fine

编辑

对于Windows,我认为问题在于您没有安装完整的Python包。因为Tkinter应该随Python一起出厂。见:http://www.tkdocs.com/tutorial/install.html

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

相关问题 更多 >