views:

930

answers:

2

hi all,

I'm new to matplotlib. My environment is WinXP, PythonWin 2.6.2, NumPy 1.3.0, matplotlib 0.98.5.3.

>>> import matplotlib.pylab as pylab
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
  File "D:\Python26\lib\site-packages\matplotlib\pylab.py", line 253, in <module>
    from matplotlib.pyplot import *
  File "D:\Python26\lib\site-packages\matplotlib\pyplot.py", line 75, in <module>
    new_figure_manager, draw_if_interactive, show = pylab_setup()
  File "D:\Python26\lib\site-packages\matplotlib\backends\__init__.py", line 25, in pylab_setup
    globals(),locals(),[backend_name])
  File "D:\Python26\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 8, in <module>
    import tkagg                 # Paint image to Tk photo blitter extension
  File "D:\Python26\lib\site-packages\matplotlib\backends\tkagg.py", line 1, in <module>
    import _tkagg
ImportError: DLL load failed: cannot find the module

I searched the web and it's said because lack of msvcp71.dll, but there is already one in my C:\windows\system32\

anyone can help? Thanks.

+3  A: 

try this, before using any other module

import matplotlib
matplotlib.use('Agg')

import matplotlib.pylab as pylab

see http://www.mail-archive.com/[email protected]/msg05372.html for more details and other ways

matplotlib can use different backends for rendering, agg is pure draw with no UI, so you can only save images e.g.

plt.savefig("plt.png")

read http://matplotlib.sourceforge.net/faq/installing_faq.html#what-is-a-backend for more details, e.g. you can output to ps, pdf, wxagg, tkagg etc, so if you have wxpython installed use this

matplotlib.use('wxagg')

also i think tkagg backend should have been work, as tkinter(http://wiki.python.org/moin/TkInter) is default gui with python, did you install python from python.org?

Anurag Uniyal
yes, with this the dll load error disappears. but nothing comes up when I typed following example scripts. it should show up a window with image, right? >>> import matplotlib >>> matplotlib.use("Agg") >>> import matplotlib.pylab as pylab >>> import matplotlib.pyplot as plt >>> plt.plot([1,2,3]) >>> plt.ylabel("some") >>> plt.show()
Daniel Wang
modified answer, see why you don't see anything
Anurag Uniyal
yes, I can save png file with "Agg". I am just curious why it cannot use "TkAgg". I am using PythonWin2.6.2, and pass the basic Tkinter test: >>> import _tkinter >>> import Tkinter >>> Tkinter._test( ). But once use("TkAgg"), import pylab fails with "DLL load failed" as in my first question. Thanks.
Daniel Wang
+1  A: 

I had the same problem installing activestat python 2.6 and pylab. After installing the sourceforge python 2.6.2 however it worked fine