本文介绍了Matplotlib 后端缺少带下划线的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用matplotlib已有一段时间了,没有任何问题.自从我需要交互式绘图功能(使用了 Tkaag)以来已经有一段时间了.从那以后,我几次更新了matplotlib.

I've been using matplotlib for some time without problems. It's been a while since i needed the interactive plot functions (for which Tkaag was used). Since then i updated matplotlib a few times.

我今天尝试使用它,但是它产生了一个错误.

I tried to use it today, but it spawned an error.

/usr/local/lib/python2.7/dist-packages/matplotlib/backends/tkagg.py in <module>()
----> 1 import _tkagg
      2 import Tkinter as Tk
      3 
      4 def blit(photoimage, aggimage, bbox=None, colormode=1):
      5     tk = photoimage.tk

ImportError: No module named _tkagg

我尝试了一个不同的后端,添加了

I tried a different backend, added the

backend      : GTKAgg

到 matplotlibrc.只是为了在其他模块上得到相同的错误.

to matplotlibrc. Just to get the same error for a different module.

ImportError: No module named _backend_gdk

当我在/usr/local/lib/python2.7/dist-packages/matplotlib/backends/中浏览后端时,我注意到所有需要的带下划线的模块都丢失了.

When I browsed for backends in /usr/local/lib/python2.7/dist-packages/matplotlib/backends/ i've noticed that all the required modules with underscore are missing.

alan@linux /usr/local/lib/python2.7/dist-packages/matplotlib/backends $ ls
backend_agg.py        backend_macosx.py    backend_template.pyc
backend_agg.pyc       backend_macosx.pyc   backend_tkagg.py
_backend_agg.so       backend_mixed.py     backend_tkagg.pyc
backend_cairo.py      backend_mixed.pyc    backend_wxagg.py
backend_cairo.pyc     backend_pdf.py       backend_wxagg.pyc
backend_cocoaagg.py   backend_pdf.pyc      backend_wx.py
backend_cocoaagg.pyc  backend_ps.py        backend_wx.pyc
backend_emf.py        backend_ps.pyc       __init__.py
backend_emf.pyc       backend_qt4agg.py    __init__.pyc
backend_fltkagg.py    backend_qt4agg.pyc   Matplotlib.nib
backend_fltkagg.pyc   backend_qt4.py       qt4_compat.py
backend_gdk.py        backend_qt4.pyc      qt4_compat.pyc
backend_gdk.pyc       backend_qtagg.py     qt4_editor
backend_gtkagg.py     backend_qtagg.pyc    tkagg.py
backend_gtkagg.pyc    backend_qt.py        tkagg.pyc
backend_gtkcairo.py   backend_qt.pyc       windowing.py
backend_gtkcairo.pyc  backend_svg.py       windowing.pyc
backend_gtk.py        backend_svg.pyc
backend_gtk.pyc       backend_template.py

我当前的matplotlib版本:

My current matplotlib version:

matplotlib      - 1.1.1        - active development (/usr/local/lib/python2.7/dist-packages)

我尝试使用以下方法卸载并重新安装matplotlib:

I've tried uninstalled and reinstalling matplotlib with:

pip uninstall matplotlib
pip install matplotlib

一切顺利.

关于重新运行交互式绘图的设置提示?

Tips on setting on getting interactive plotting running again?

    BUILDING MATPLOTLIB

                matplotlib: 1.1.1

                    python: 2.7.3rc2 (default, Apr 22 2012, 22:35:38)  [GCC

                            4.6.3]

                  platform: linux2



    REQUIRED DEPENDENCIES

                     numpy: 1.6.2

                 freetype2: 14.1.8



    OPTIONAL BACKEND DEPENDENCIES

                    libpng: 1.2.49

                   Tkinter: no

                            * Using default library and include directories for

                            * Tcl and Tk because a Tk window failed to open.

                            * You may need to define DISPLAY for Tk to work so

                            * that setup can determine where your libraries are

                            * located. Tkinter present, but header files are not

                            * found. You may need to install development

                            * packages.

                pkg-config: looking for pygtk-2.0 gtk+-2.0

                            * Package pygtk-2.0 was not found in the pkg-config

                            * search path. Perhaps you should add the directory

                            * containing `pygtk-2.0.pc' to the PKG_CONFIG_PATH

                            * environment variable No package 'pygtk-2.0' found

                            * Package gtk+-2.0 was not found in the pkg-config

                            * search path. Perhaps you should add the directory

                            * containing `gtk+-2.0.pc' to the PKG_CONFIG_PATH

                            * environment variable No package 'gtk+-2.0' found

                            * You may need to install 'dev' package(s) to

                            * provide header files.

                      Gtk+: no

                            * Could not find Gtk+ headers in any of

                            * '/usr/local/include', '/usr/include', '.'

           Mac OS X native: no

                        Qt: no

                       Qt4: Qt: 4.8.1, PyQt4: 4.9.1

                    PySide: no

                     Cairo: 1.8.8



    OPTIONAL DATE/TIMEZONE DEPENDENCIES

                  datetime: present, version unknown

                  dateutil: matplotlib will provide

                      pytz: matplotlib will provide

    adding pytz



    OPTIONAL USETEX DEPENDENCIES

                    dvipng: 1.14

               ghostscript: 9.05

                     latex: 3.1415926

                   pdftops: 0.18.4

推荐答案

感谢 peison 的评论,我检查了 matplotlib 的安装日志,它显示了很多依赖项.

Thanks to peison's comment I've checked the installation log for matplotlib and it showed lots of dependencies.

我之前没有注意到,因为使用整个安装过程运行非常快

I haven't noticed that before because the whole process of instalation ran really fast using

pip install matplotlib

并以成功安装结束.

回答问题.解决方案是安装软件包tk和tk-dev,然后重建matplotlib.

To answer the question. The solution was to install packages tk and tk-dev, and rebuild matplotlib.

这篇关于Matplotlib 后端缺少带下划线的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 05:01