【python】ImportError: No module named '_tkinter', please install the python3-tk package

在python3.6下运行程序报错:

File "/usr/lib/python3.6/tkinter/__init__.py", line 37, in 
    import _tkinter
ModuleNotFoundError: No module named '_tkinter'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "main.py", line 1, in 
    from test.env import *
  File "/home/test/env.py", line 2, in 
    import matplotlib.pyplot as plt
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/pyplot.py", line 115, in 
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/backends/__init__.py", line 62, in pylab_setup
    [backend_name], 0)
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/backends/backend_tkagg.py", line 4, in 
    from . import tkagg  # Paint image to Tk photo blitter extension.
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/backends/tkagg.py", line 5, in 
    from six.moves import tkinter as Tk
  File "/usr/local/lib/python3.6/dist-packages/six.py", line 92, in __get__
    result = self._resolve()
  File "/usr/local/lib/python3.6/dist-packages/six.py", line 115, in _resolve
    return _import_module(self.mod)
  File "/usr/local/lib/python3.6/dist-packages/six.py", line 82, in _import_module
    __import__(name)
  File "/usr/lib/python3.6/tkinter/__init__.py", line 39, in 
    raise ImportError(str(msg) + ', please install the python3-tk package')
ImportError: No module named '_tkinter', please install the python3-tk package

根据这个报错信息尝试安装python3-tk,无对应包。

仔细查看错误信息是与matplotlib包有关,可能是配置问题,重新安装此包:

pip uninstall matplotlib
pip install matplotlib

重新运行程序,成功!

你可能感兴趣的:(Bug记录)