Saving a plot in Mac OS X backend crashes IPython #2710

Closed
asmeurer opened this Issue Dec 20, 2012 · 5 comments

Comments

Projects
None yet
3 participants
@asmeurer
Contributor

asmeurer commented Dec 20, 2012

I created a plot and clicked the save button (in the Mac OS X backend), and after choosing save, IPython crashes. Here's the full traceback:

Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34) 
Type "copyright", "credits" or "license" for more information.

IPython 0.14.dev -- 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.

Welcome to pylab, a matplotlib-based Python environment [backend: MacOSX].
For more information, type 'help(pylab)'.

In [1]: plot([1])
Out[1]: [<matplotlib.lines.Line2D at 0x1060bb250>]

In [2]: 2012-12-20 15:12:11.733 Python[68329:f07] CFPropertyListCreateFromXMLData(): Old-style plist parser: missing semicolon in dictionary on line 3. Parsing will be abandoned. Break on _CFPropertyListMissingSemicolon to debug.
libpng warning: Application was compiled with png.h from libpng-1.5.11
libpng warning: Application  is  running with png.c from libpng-1.4.11
libpng warning: Incompatible libpng version in application and library
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py", line 470, in save_figure
    self.canvas.print_figure(filename)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backend_bases.py", line 2125, in print_figure
    **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backend_bases.py", line 1884, in print_png
    return agg.print_png(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 503, in print_png
    filename_or_obj, self.figure.dpi)
RuntimeError: Could not create write struct

If you suspect this is an IPython bug, please report it at:
    https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev@scipy.org

You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.

Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
    %config Application.verbose_crash=True

%config Application.verbose_crash=True

In [3]: %config Application.verbose_crash=True

In [4]: plot([1])
Out[4]: [<matplotlib.lines.Line2D at 0x106425510>]

In [5]: libpng warning: Application was compiled with png.h from libpng-1.5.11
libpng warning: Application  is  running with png.c from libpng-1.4.11
libpng warning: Incompatible libpng version in application and library
---------------------------------------------------------------------------
RuntimeErrorPython 2.7.2: /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
                                                   Thu Dec 20 15:12:50 2012
A problem occured executing Python code.  Here is the sequence of function
calls leading up to the error, with the most recent (innermost) call last.
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.pyc in save_figure(self=NavigationToolbar2 object 0x1054b7520, *args=())
    455 
    456     def draw_rubberband(self, event, x0, y0, x1, y1):
    457         self.canvas.set_rubberband(int(x0), int(y0), int(x1), int(y1))
    458 
    459     def release(self, event):
    460         self.canvas.remove_rubberband()
    461 
    462     def set_cursor(self, cursor):
    463         _macosx.set_cursor(cursor)
    464 
    465     def save_figure(self, *args):
    466         filename = _macosx.choose_save_file('Save the figure',
    467                                             self.canvas.get_default_filename())
    468         if filename is None: # Cancel
    469             return
--> 470         self.canvas.print_figure(filename)
        self.canvas.print_figure = <bound method FigureCanvasMac.print_figure of FigureCanvas object 0x1054b2830 wrapping NSView 0x105647340>
        filename = u'/Users/aaronmeurer/Desktop/figure_1.png'
    471 
    472     def prepare_configure_subplots(self):
    473         toolfig = Figure(figsize=(6,3))
    474         canvas = FigureCanvasMac(toolfig)
    475         toolfig.subplots_adjust(top=0.9)
    476         tool = SubplotTool(self.canvas.figure, toolfig)
    477         return canvas
    478 
    479     def set_message(self, message):
    480         _macosx.NavigationToolbar2.set_message(self, message.encode('utf-8'))
    481 
    482     def dynamic_update(self):
    483         self.canvas.draw_idle()
    484 
    485 ########################################################################

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backend_bases.pyc in print_figure(self=FigureCanvas object 0x1054b2830 wrapping NSView 0x105647340, filename=u'/Users/aaronmeurer/Desktop/figure_1.png', dpi=100, facecolor='w', edgecolor='w', orientation='portrait', format=u'png', **kwargs={})
   2110                                                   bbox_inches)
   2111 
   2112             _bbox_inches_restore = (bbox_inches, restore_bbox)
   2113         else:
   2114             _bbox_inches_restore = None
   2115 
   2116         try:
   2117             #result = getattr(self, method_name)(
   2118             result = print_method(
   2119                 filename,
   2120                 dpi=dpi,
   2121                 facecolor=facecolor,
   2122                 edgecolor=edgecolor,
   2123                 orientation=orientation,
   2124                 bbox_inches_restore=_bbox_inches_restore,
-> 2125                 **kwargs)
        kwargs = {}
   2126         finally:
   2127             if bbox_inches and restore_bbox:
   2128                 restore_bbox()
   2129 
   2130             self.figure.dpi = origDPI
   2131             self.figure.set_facecolor(origfacecolor)
   2132             self.figure.set_edgecolor(origedgecolor)
   2133             self.figure.set_canvas(self)
   2134             #self.figure.canvas.draw() ## seems superfluous
   2135         return result
   2136 
   2137     def get_default_filetype(self):
   2138         """
   2139         Get the default savefig file format as specified in rcParam
   2140         ``savefig.format``. Returned string excludes period. Overridden

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backend_bases.pyc in print_png(self=FigureCanvas object 0x1054b2830 wrapping NSView 0x105647340, *args=(u'/Users/aaronmeurer/Desktop/figure_1.png',), **kwargs={'bbox_inches_restore': None, 'dpi': 100, 'edgecolor': 'w', 'facecolor': 'w', 'orientation': 'portrait'})
   1869         return ps.print_eps(*args, **kwargs)
   1870 
   1871     def print_pdf(self, *args, **kwargs):
   1872         from backends.backend_pdf import FigureCanvasPdf  # lazy import
   1873         pdf = self.switch_backends(FigureCanvasPdf)
   1874         return pdf.print_pdf(*args, **kwargs)
   1875 
   1876     def print_pgf(self, *args, **kwargs):
   1877         from backends.backend_pgf import FigureCanvasPgf  # lazy import
   1878         pgf = self.switch_backends(FigureCanvasPgf)
   1879         return pgf.print_pgf(*args, **kwargs)
   1880 
   1881     def print_png(self, *args, **kwargs):
   1882         from backends.backend_agg import FigureCanvasAgg  # lazy import
   1883         agg = self.switch_backends(FigureCanvasAgg)
-> 1884         return agg.print_png(*args, **kwargs)
        agg.print_png = <bound method FigureCanvasAgg.print_png of <matplotlib.backends.backend_agg.FigureCanvasAgg object at 0x1060c6090>>
        args = (u'/Users/aaronmeurer/Desktop/figure_1.png',)
        kwargs = {'edgecolor': 'w', 'bbox_inches_restore': None, 'orientation': 'portrait', 'dpi': 100, 'facecolor': 'w'}
   1885 
   1886     def print_ps(self, *args, **kwargs):
   1887         from backends.backend_ps import FigureCanvasPS  # lazy import
   1888         ps = self.switch_backends(FigureCanvasPS)
   1889         return ps.print_ps(*args, **kwargs)
   1890 
   1891     def print_raw(self, *args, **kwargs):
   1892         from backends.backend_agg import FigureCanvasAgg  # lazy import
   1893         agg = self.switch_backends(FigureCanvasAgg)
   1894         return agg.print_raw(*args, **kwargs)
   1895     print_bmp = print_rgb = print_raw
   1896 
   1897     def print_svg(self, *args, **kwargs):
   1898         from backends.backend_svg import FigureCanvasSVG  # lazy import
   1899         svg = self.switch_backends(FigureCanvasSVG)

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_agg.pyc in print_png(self=<matplotlib.backends.backend_agg.FigureCanvasAgg object>, filename_or_obj=<closed file u'/Users/aaronmeurer/Desktop/figure_1.png', mode 'wb'>, *args=(), **kwargs={'bbox_inches_restore': None, 'dpi': 100, 'edgecolor': 'w', 'facecolor': 'w', 'orientation': 'portrait'})
    488     print_rgba = print_raw
    489 
    490     def print_png(self, filename_or_obj, *args, **kwargs):
    491         FigureCanvasAgg.draw(self)
    492         renderer = self.get_renderer()
    493         original_dpi = renderer.dpi
    494         renderer.dpi = self.figure.dpi
    495         if is_string_like(filename_or_obj):
    496             filename_or_obj = open(filename_or_obj, 'wb')
    497             close = True
    498         else:
    499             close = False
    500         try:
    501             _png.write_png(renderer._renderer.buffer_rgba(),
    502                            renderer.width, renderer.height,
--> 503                            filename_or_obj, self.figure.dpi)
        filename_or_obj = <closed file u'/Users/aaronmeurer/Desktop/figure_1.png', mode 'wb' at 0x106435390>
        self.figure.dpi = 80
    504         finally:
    505             if close:
    506                 filename_or_obj.close()
    507         renderer.dpi = original_dpi
    508 
    509     def print_to_buffer(self):
    510         FigureCanvasAgg.draw(self)
    511         renderer = self.get_renderer()
    512         original_dpi = renderer.dpi
    513         renderer.dpi = self.figure.dpi
    514         result = (renderer._renderer.buffer_rgba(),
    515                   (int(renderer.width), int(renderer.height)))
    516         renderer.dpi = original_dpi
    517         return result

RuntimeError: Could not create write struct

**********************************************************************

Oops, ipython crashed. We do our best to make it stable, but...

A crash report was automatically generated with the following information:
  - A verbatim copy of the crash traceback.
  - A copy of your input history during this session.
  - Data on your current ipython configuration.

It was left in the file named:
    '/Users/aaronmeurer/.ipython/Crash_report_ipython.txt'
If you can email this file to the developers, the information in it will help
them in understanding and correcting the problem.

You can mail it to: Fernando Perez at ipython-dev@scipy.org
with the subject 'ipython Crash Report'.

If you want to do it now, the following command will work (under Unix):
mail -s 'ipython Crash Report' ipython-dev@scipy.org < /Users/aaronmeurer/.ipython/Crash_report_ipython.txt

To ensure accurate tracking of this issue, please file a report about it at:
https://github.com/ipython/ipython/issues

Error in sys.excepthook:
Traceback (most recent call last):
  File "IPython/core/application.py", line 173, in excepthook
    return self.crash_handler(etype, evalue, tb)
  File "IPython/core/crashhandler.py", line 179, in __call__
    raw_input("Hit <Enter> to quit (your terminal may close):")
RuntimeError: can't re-enter readline

Original exception was:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py", line 470, in save_figure
    self.canvas.print_figure(filename)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backend_bases.py", line 2125, in print_figure
    **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backend_bases.py", line 1884, in print_png
    return agg.print_png(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 503, in print_png
    filename_or_obj, self.figure.dpi)
RuntimeError: Could not create write struct

This is with git master matplotlib.

May be the same as #2652; that wasn't very detailed.

By the way, is the "Email Fernando Perez" line still supposed to be there?

I uploaded the "image" that it saved here:

figure_1

@asmeurer

This comment has been minimized.

Show comment Hide comment
@asmeurer

asmeurer Dec 20, 2012

Contributor

Also, note that it didn't actually "crash" IPython, in that it still worked. But the image never did save correctly.

Contributor

asmeurer commented Dec 20, 2012

Also, note that it didn't actually "crash" IPython, in that it still worked. But the image never did save correctly.

@asmeurer

This comment has been minimized.

Show comment Hide comment
@asmeurer

asmeurer Dec 20, 2012

Contributor

Oh, and I guess the "image" is just an empty file.

Contributor

asmeurer commented Dec 20, 2012

Oh, and I guess the "image" is just an empty file.

@Sharpie

This comment has been minimized.

Show comment Hide comment
@Sharpie

Sharpie Dec 21, 2012

I'll bet your problem is that you have a couple incompatible versions of libPNG running around:

libpng warning: Application was compiled with png.h from libpng-1.5.11
libpng warning: Application is running with png.c from libpng-1.4.11
libpng warning: Incompatible libpng version in application and library

Basically, your version of matplotlib is trying to use v 1.4.11 of libPNG as if it were v. 1.5.11 and naturally things go pear shaped.

Sharpie commented Dec 21, 2012

I'll bet your problem is that you have a couple incompatible versions of libPNG running around:

libpng warning: Application was compiled with png.h from libpng-1.5.11
libpng warning: Application is running with png.c from libpng-1.4.11
libpng warning: Incompatible libpng version in application and library

Basically, your version of matplotlib is trying to use v 1.4.11 of libPNG as if it were v. 1.5.11 and naturally things go pear shaped.

@asmeurer

This comment has been minimized.

Show comment Hide comment
@asmeurer

asmeurer Dec 21, 2012

Contributor

I do seem to have both, but I can't remove libpng 1.4 because apparently inkscape depends on it. I have them both installed through Fink.

Contributor

asmeurer commented Dec 21, 2012

I do seem to have both, but I can't remove libpng 1.4 because apparently inkscape depends on it. I have them both installed through Fink.

@minrk

This comment has been minimized.

Show comment Hide comment
@minrk

minrk Jan 19, 2013

Owner

I can confirm that saving images with the OS X backend works just fine in master. I don't think there's anything we can do about your borked environment with conflicting libpng versions. You just have to do PATH / LD_LIBRARY_PATH shenanigans to make sure the right ones are loaded.

By the way, is the "Email Fernando Perez" line still supposed to be there?

No, definitely not. I will fix that.

Owner

minrk commented Jan 19, 2013

I can confirm that saving images with the OS X backend works just fine in master. I don't think there's anything we can do about your borked environment with conflicting libpng versions. You just have to do PATH / LD_LIBRARY_PATH shenanigans to make sure the right ones are loaded.

By the way, is the "Email Fernando Perez" line still supposed to be there?

No, definitely not. I will fix that.

@minrk minrk closed this Jul 4, 2013

@minrk minrk added this to the no action milestone Mar 26, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment