ImportError: No module named backend_tkagg

心已入冬 提交于 2019-11-29 06:32:01

I've seen this before, also on openSUSE (12.3). The fix is to edit the default matplotlibrc file.

Here's how you find where the default matplotlibrc file lives, and where it lives on my machine:

>>> import matplotlib
>>> matplotlib.matplotlib_fname()
'/usr/lib64/python2.7/site-packages/matplotlib/mpl-data/matplotlibrc'

The backend setting is the first configuration option in this file. Change it from TkAgg to Agg, or to some other backend you have installed on your system. The comments in the matplotlibrc file list all backends supported by matplotlib.

The backend specified in this file is only the default; you can still change it at runtime by adding the following two lines, before any other matplotlib import:

import matplotlib
matplotlib.use("Agg")  # or whichever backend you wish to use

I use openSuse 13.1 and had the same error "ImportError: No module named backend_tkagg".

I solved it by using this suggestion: http://forums.opensuse.org/showthread.php/416182-Python-matplolib.

I've installed the python-matplotlib-tk package, and now it is working just fine.

E.g. you can use: zypper install python-matplotlib-tk

I tried various solutions, only this works for me:

sudo pip install matplotlib --upgrade

I was able to fix this by putting

import matplotlib.backends.backend_tkagg

above

import matplotlib.pyplot as plt

Note, I received the same error while trying to run an executable generated using Py2exe.

Here is what I got when I ran TheProgram.exe from the command prompt:

>>TheProgram.exe
Traceback (most recent call last):
  File "ThePythonScriptToMakeIntoExe.py", line 14, in <module>
  File "C:\Python34\lib\site-packages\matplotlib\pyplot.py", line 109, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "C:\Python34\lib\site-packages\matplotlib\backends\__init__.py", line 32, in pylab_setup
    globals(),locals(),[backend_name],0)
ImportError: No module named 'matplotlib.backends.backend_tkagg'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!