导入matplotlib.pyplot时,出现关于python-tk的错误

3 投票
3 回答
4754 浏览
提问于 2025-04-18 09:56

我尝试导入matplotlib.pyplot这个库,但遇到了一个错误,提示说没有安装python-tk。看起来这个库已经安装了,但我还是收到了这个错误。希望能得到一些帮助。下面是更多的信息,输出内容在这里。非常感谢。

    $ ipython
    Python 2.7.7 (default, Jun  3 2014, 16:16:56)
    Type "copyright", "credits" or "license" for more information.

    IPython 2.1.0 -- An enhanced Interactive Python.
    ?         -> Introduction and overview of IPython's features.
    %quickref -> Quick reference.
    help      -> Python's own help system.
    object?   -> Details about 'object', use 'object??' for extra details.

    In [1]: import numpy as np

    In [2]: import matplotlib.pyplot as plt
    ---------------------------------------------------------------------------
    ImportError                               Traceback (most recent call last)
    <ipython-input-2-eff513f636fd> in <module>()
    ----> 1 import matplotlib.pyplot as plt

    /usr/lib/pymodules/python2.7/matplotlib/pyplot.py in <module>()
         96
         97 from matplotlib.backends import pylab_setup
    ---> 98 _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
         99
        100

    /usr/lib/pymodules/python2.7/matplotlib/backends/__init__.pyc in pylab_setup()
         26     # imports. 0 means only perform absolute imports.
         27     backend_mod = __import__(backend_name,
    ---> 28                              globals(),locals(),[backend_name],0)
         29
         30     # Things we pull in from all backends

    /usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py in <module>()
          6 import os.path
          7
    ----> 8 import Tkinter as Tk, FileDialog
          9
         10 # Paint image to Tk photo blitter extension

    /usr/lib/python2.7/lib-tk/Tkinter.py in <module>()
         40     import _tkinter
         41 except ImportError, msg:
    ---> 42     raise ImportError, str(msg) + ', please install the python-tk package'
         43 tkinter = _tkinter # b/w compat for export
         44 TclError = _tkinter.TclError

    ImportError: libBLT.2.4.so.8.5: cannot open shared object file: No such file or directory, please install the python-tk package

3 个回答

1

查看Debian的错误报告:https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=751767(据我所知,matplotlib并不依赖于“blt”这个东西)

3

作为一个临时解决办法,你可以在

mv libBLT.2.4.so.8.6 libBLT.2.4.so.8.5

这个路径下放东西,应该就能正常工作了。

5

没有这样的文件或目录,请安装 python-tk 这个软件包

你可以通过下面的命令来安装这个软件包:

sudo apt-get install python-tk

撰写回答