ubuntu下使用python3的有些库时,解决"raise ImportError(str(msg) + ', please install the python3-tk package') ImportError: No module named '_tkinter', please install the python3-tk package"的错误

问题:

在Ubuntu下使用matplotlib这个库时,运行时出现如下错误:

raise ImportError(str(msg) + ', please install the python3-tk package')
ImportError: No module named '_tkinter', please install the python3-tk package

原因:

ubuntu下使用python3的有些库时,解决"raise ImportError(str(msg) + ', please install the python3-tk package') ImportError: No module named '_tkinter', please install the python3-tk package"的错误

从错误提示我们可以看到原因是:是由于python的版本没有包含tkinter的模块,只需要把tk的package安装就可以了。

解决方案:

终端输入命令进行安装:

sudo apt-get install python3-tk

再次运行,就会发现没有错误了。