matplotlib pyplot doesnt plot. Fails with module not found python3-tk
我正在尝试使用pyplot绘图:
当我尝试执行我的脚本时。 它抱怨找不到python3-tk模块。 我知道需要安装此软件包才能使其正常工作。 有解决方法吗?
Traceback (most recent call last): File
"/home/user1/PycharmProjects/programs/frequency.py", line 81, infrom matplotlib import pyplot as plt File"/home/user1/PycharmProjects/programs/venv/lib/python3.5/site-packages/matplotlib/pyplot.py",
line 115, in
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup() File
"/home/user1/PycharmProjects/programs/venv/lib/python3.5/site-packages/matplotlib/backends/init.py",
line 62, in pylab_setup
[backend_name], 0) File"/home/user1/PycharmProjects/programs/venv/lib/python3.5/site-packages/matplotlib/backends/backend_tkagg.py",
line 4, in
from . import tkagg # Paint image to Tk photo blitter extension. File
"/home/user1/PycharmProjects/programs/venv/lib/python3.5/site-packages/matplotlib/backends/tkagg.py",
line 5, in
from six.moves import tkinter as Tk File"/home/user1/PycharmProjects/programs/venv/lib/python3.5/site-packages/six.py",
line 92, in get
result = self._resolve() File"/home/user1/PycharmProjects/programs/venv/lib/python3.5/site-packages/six.py",
line 115, in _resolve
return _import_module(self.mod) File"/home/user1/PycharmProjects/programs/venv/lib/python3.5/site-packages/six.py",
line 82, in _import_module
import(name) File"/usr/lib/python3.5/tkinter/init.py", line 38, in
raise ImportError(str(msg) + ', please install the python3-tk package') ImportError: No module named '_tkinter', please install the
python3-tk package
如果您使用的是Python 3,请尝试:
1 | sudo apt-get install python3-tk |
如果Python版本是3.6:
1 | sudo apt-get install python3.6-tk |
1 | sudo add-apt-repository ppa:deadsnakes/ppa |
你可以参考这个问题。
https://github.com/ufoym/deepo/issues/17
尝试使用此代码
1 2 | import matplotlib matplotlib.use('agg') |
Dalton建议最好安装python3-tk。