【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 <module>
    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 <module>
    from test.env import *
  File "/home/test/env.py", line 2, in <module>
    import matplotlib.pyplot as plt
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/pyplot.py", line 115, in <module>
    _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 <module>
    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 <module>
    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 <module>
    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

重新运行程序,成功!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值