Error saving to pdf with savefig on Mac OS X 10.6.7 (Snow Leopard)

Dear List,

I use Matplotlib bundled with the Enthought Python Distribution (EPD) (both 32-bit and 64-bit versions). After a recent update, I find that my Python code (run either in a iPython shell or in bash shell) crashes while attempting to save figures to pdf files using savefig(). However, saving to other formats (png, ps, eps or svg) works fine. The error message echoed to the terminal are "Bus error" with 32-bit EPD and "Abort trap" with 64-bit EPD. Also, converting to pdf from one of the other four formats using *nix utilities like convert or ps2pdf go through fine (prompting to suspect that savefig has a bug). Unfortunately, in a short time, by looking at pyplot.py, I couldn't determine what could be causing this. Therefore, it would be really helpful if list members can provide any hints to fix this. I need to save a bunch of figures from existing code, and it would be great if I could do so without having to modify all savefig statements; additionally, I would prefer not to write a shell script to perform the conversions to pdf considering the different directories that my figures are saved to.

Also, a few searches using google did not throw up anything useful (although one relevant list archive suggested that if EPD alone is installed on a Mac, this error shouldn't be seen. Since this is the case for me, it didn't help.). The following are my specifications:

Platform: Mac OS X 10.6.7
Python version: 2.7.1
Matplotlib version: 1.0.1
EPD versions: 7.0-2 (both 32-bit and 64-bit)

(Should I also post this to matplotlib-devel ?)

Thanks and Regards,
Kaushik Kalyanaraman

Dear List,

I use Matplotlib bundled with the Enthought Python Distribution (EPD) (both 32-bit and 64-bit versions). After a recent update, I find that my Python code (run either in a iPython shell or in bash shell) crashes while attempting to save figures to pdf files using savefig(). However, saving to other formats (png, ps, eps or svg) works fine. The error message echoed to the terminal are "Bus error" with 32-bit EPD and "Abort trap" with 64-bit EPD. Also, converting to pdf from one of the other four formats using *nix utilities like convert or ps2pdf go through fine (prompting to suspect that savefig has a bug). Unfortunately, in a short time, by looking at pyplot.py, I couldn't determine what could be causing this. Therefore, it would be really helpful if list members can provide any hints to fix this. I need to save a bunch of figures from existing code, and it would be great if I could do so without having to modify all savefig statements; additionally, I would prefer not to

wr

  ite a shell script to perform the conversions to pdf considering the different directories that my figures are saved to.

Also, a few searches using google did not throw up anything useful (although one relevant list archive suggested that if EPD alone is installed on a Mac, this error shouldn't be seen. Since this is the case for me, it didn't help.). The following are my specifications:

Platform: Mac OS X 10.6.7
Python version: 2.7.1
Matplotlib version: 1.0.1
EPD versions: 7.0-2 (both 32-bit and 64-bit)

(Should I also post this to matplotlib-devel ?)

Probably not necessary; I think most of us on -devel read -users, and other people on -users may have useful insight and testing to contribute.

The pdf backend is not that different from the ps and svg backends, at least superficially--all of them are just python code that write files--so it is not obvious why it would cause the sort of problem that is usually associated with broken extension code.

Do you see the problem with any plot at all? E.g.,

import matplotlib
matplotlib.use("pdf")
import matplotlib.pyplot as plt
plt.plot([1,2])
plt.savefig("test.pdf")

My guess is that somehow something is getting confused between the two EPD versions, or something got confused during the update.

Can you eliminate all traces of EPD, and then just cleanly install one version, and see if the problem still appears?

Eric

···

On 05/08/2011 08:58 AM, Kaushik Kalyanaraman wrote:

Thanks and Regards,
Kaushik Kalyanaraman

------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network
management toolset available today. Delivers lowest initial
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Hello Eric,

Thanks for your reply and suggestions!

Do you see the problem with any plot at all? E.g.,

<snip>

Can you eliminate all traces of EPD, and then just cleanly install one version, and see if the problem still appears?

I cleanly installed EPD. Now, with only a single version (EPD 7.0-2, Python 2.7.1), I find that, interestingly,

a) In the 32-bit version (both when independent of and concurrent with 64-bit EPD), simply calling plot() crashes Python, both in bash and IPython shells.
b) In the 64-bit version, plot() goes through and creates the correct plot window but savefig() causes a crash when attempting to save in any format (pdf, ps, svg, png).

As in my original mail the error messages echoed to terminal are "Abort trap" and "Bus error" for 64-bit and 32-bit versions, respectively.

Thus, I wish to believe that there is some bug in matplotlib which is possibly not local to savefig() alone (at least for the 32-bit version). In this regard, I wish to request you as well as list members to advise me as to whether I should use version 1.0.0 ? If so, should I build from source or can I simply use the disk image file (and have it easy!) if I wish to replace the EPD bundled matplotlib ?

Thanks and Regards,
Kaushik

Hello Eric,

Thanks for your reply and suggestions!

Do you see the problem with any plot at all? E.g.,

<snip>

Can you eliminate all traces of EPD, and then just cleanly install one version, and see if the problem still appears?

I cleanly installed EPD. Now, with only a single version (EPD 7.0-2, Python 2.7.1), I find that, interestingly,

a) In the 32-bit version (both when independent of and concurrent with 64-bit EPD), simply calling plot() crashes Python, both in bash and IPython shells.
b) In the 64-bit version, plot() goes through and creates the correct plot window but savefig() causes a crash when attempting to save in any format (pdf, ps, svg, png).

As in my original mail the error messages echoed to terminal are "Abort trap" and "Bus error" for 64-bit and 32-bit versions, respectively.

Thus, I wish to believe that there is some bug in matplotlib which is possibly not local to savefig() alone (at least for the 32-bit version). In this regard, I wish to request you as well as list members to advise me as to whether I should use version 1.0.0 ? If so, should I build from source or can I simply use the disk image file (and have it easy!) if I wish to replace the EPD bundled matplotlib ?

No, I don't think this is a bug in matplotlib; there are many mpl users, and at least to some extent some devs, who use Macs, so if this were a general bug in 1.0.1 it would have turned up long ago. Similarly, I doubt it is the case that EPD is simply broken. I would be surprised if Enthought did not test EPD versions prior to release! Most likely there is something out of the ordinary about your particular system that is causing the problem; there is still a version conflict or corrupted file somewhere.

Did you try saving the code snippet in my last message to a file, and running it? The point of it was to eliminate the use of an interactive backend.

I don't have any more ideas; maybe someone else can suggest the next troubleshooting steps.

Eric

···

On 05/08/2011 11:42 AM, Kaushik Kalyanaraman wrote:

Thanks and Regards,
Kaushik
------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network
management toolset available today. Delivers lowest initial
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Hello Eric,

Thanks to you, the problem is resolved!

No, I don't think this is a bug in matplotlib; there are many mpl users,
and at least to some extent some devs, who use Macs, so if this were a
general bug in 1.0.1 it would have turned up long ago.

Since you were convinced that mpl is not buggy, I decided to look at EPD. However, before that, and for the record, yes, I did try running your commands by saving them to a file and by invoking
$Python foo.py
in my bash shell (where Python was the 64-bit python or path to the 32-bit python). This still caused the crashes, and may not have helped in locating the actual snag.

Similarly, I doubt it is the case that EPD is simply broken. I would be surprised if
Enthought did not test EPD versions prior to release!

There is a very recent thread in epd-users that is similar in flavor to my problem https://mail.enthought.com/pipermail/epd-users/2011-May/000379.html. As in that thread, I too had my DYLD_LIBRARY_PATH set to something in .profile, in my case simply /usr/local/lib. I do not know whether I set it (possibly for CVXOPT to work) or whether an earlier version of EPD installer or some other installer added it. In any case, not having it defined solved my problem (at least this one; don't know if it would break something else though!).

By the way, I know that this particular environment variable has been around in my .profile for quite some time now, so I suspect that something changed in EPD 7.0-2 that causes the trouble (does not appear evident from their change log though). Again, for the record, less than three weeks ago, on EPD 7.0-1, everything was working smoothly. Also, I shall bring this discussion to the attention of those in the epd-users' thread.

Thanks again!

-Kaushik