saving PNG graphics on mac

For some reason when trying to save in PNG format on OS X 10.5.2, a window pops up with the error:

Matplotlib backend_wx error
cannot return std::string from Unicode object

This is with the simple scipy demo at http://www.scipy.org/Cookbook/OptimizationDemo1

Gideon Simpson
Department of Applied Physics & Applied Mathematics
Columbia University
grs2103@...1353...

Are you sure you built pylab correctly? See if you can find something
suspicious in the build dialog. I had this error once a long time ago,
but at some point since then a rebuild of everything fixed it. In the
mean time, using savefig will still work even if the GUI button
doesn't.

Josh

···

On Sat, Apr 12, 2008 at 11:41 AM, Gideon Simpson <grs2103@...1353...> wrote:

For some reason when trying to save in PNG format on OS X 10.5.2, a
window pops up with the error:

Matplotlib backend_wx error
cannot return std::string from Unicode object

This is with the simple scipy demo at http://www.scipy.org/Cookbook/OptimizationDemo1

Gideon Simpson
Department of Applied Physics & Applied Mathematics
Columbia University
grs2103@...1353...

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

I don't see any error when I run python setup.py build for matplotlib. It seems to identify everything it needs.
-gideon

···

On Apr 13, 2008, at 10:35 AM, Joshua Lippai wrote:

Are you sure you built pylab correctly? See if you can find something
suspicious in the build dialog. I had this error once a long time ago,
but at some point since then a rebuild of everything fixed it. In the
mean time, using savefig will still work even if the GUI button
doesn't.

Josh

On Sat, Apr 12, 2008 at 11:41 AM, Gideon Simpson > <grs2103@...1353...> wrote:

For some reason when trying to save in PNG format on OS X 10.5.2, a
window pops up with the error:

Matplotlib backend_wx error
cannot return std::string from Unicode object

This is with the simple scipy demo at http://www.scipy.org/Cookbook/OptimizationDemo1

Gideon Simpson
Department of Applied Physics & Applied Mathematics
Columbia University
grs2103@...1353...

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

I know I had some matplotlib trouble in terms of compiling on OS X
Leopard before I changed the Makefile inside

/Library/Frameworks/Python.framework/Versions/Current/lib/python2.5/config/

If you're on an Intel Mac, try downloading the beta Apple GCC 4.2 from
http://developer.apple.com and alter the Makefile so that CC and CXX
are set to /usr/bin/gcc-4.2 and /usr/bin/g++-4.2 respectively. Also
remove the flag "-arch ppc" from both the BASEFLAGS and LDFLAGS
sections, and remove "-Wno-long-double" flag from the BASEFLAGS
section.

This assumes you're using the MacPython installation of Python and not
the standard one provided by Apple. I personally wouldn't recommend
using the standard Apple installation because a lot of modules assume
you have the Python Framework in /Library/Frameworks/ due to that
being the de facto standard set by MacPython and ActiveState Python.
In addition, the MacPython instalation provides Python 2.5.2, not just
2.5.1.

Matplotlib aside, you might want to make sure you installed the
Unicode version of wxWidgets, and reinstall it if necessary.

Josh

···

On Sun, Apr 13, 2008 at 3:12 PM, Gideon Simpson <grs2103@...1353...> wrote:

I don't see any error when I run python setup.py build for matplotlib. It
seems to identify everything it needs.
-gideon

On Apr 13, 2008, at 10:35 AM, Joshua Lippai wrote:

> Are you sure you built pylab correctly? See if you can find something
> suspicious in the build dialog. I had this error once a long time ago,
> but at some point since then a rebuild of everything fixed it. In the
> mean time, using savefig will still work even if the GUI button
> doesn't.
>
> Josh
>
> On Sat, Apr 12, 2008 at 11:41 AM, Gideon Simpson <grs2103@...1353...> > wrote:
>
> > For some reason when trying to save in PNG format on OS X 10.5.2, a
> > window pops up with the error:
> >
> > Matplotlib backend_wx error
> > cannot return std::string from Unicode object
> >
> >
> > This is with the simple scipy demo at
http://www.scipy.org/Cookbook/OptimizationDemo1
> >
> >
> > Gideon Simpson
> > Department of Applied Physics & Applied Mathematics
> > Columbia University
> > grs2103@...1353...
> >
> >
> >
-------------------------------------------------------------------------
> > This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
> > Don't miss this year's exciting event. There's still time to save $100.
> > Use priority code J8TL2D2.
> >
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
> > _______________________________________________
> > Matplotlib-users mailing list
> > Matplotlib-users@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> >
> >
>

wxPython, rather.

Josh

···

On Sun, Apr 13, 2008 at 5:41 PM, Joshua Lippai <discerptor@...287...> wrote:

I know I had some matplotlib trouble in terms of compiling on OS X
Leopard before I changed the Makefile inside

/Library/Frameworks/Python.framework/Versions/Current/lib/python2.5/config/

If you're on an Intel Mac, try downloading the beta Apple GCC 4.2 from
http://developer.apple.com and alter the Makefile so that CC and CXX
are set to /usr/bin/gcc-4.2 and /usr/bin/g++-4.2 respectively. Also
remove the flag "-arch ppc" from both the BASEFLAGS and LDFLAGS
sections, and remove "-Wno-long-double" flag from the BASEFLAGS
section.

This assumes you're using the MacPython installation of Python and not
the standard one provided by Apple. I personally wouldn't recommend
using the standard Apple installation because a lot of modules assume
you have the Python Framework in /Library/Frameworks/ due to that
being the de facto standard set by MacPython and ActiveState Python.
In addition, the MacPython instalation provides Python 2.5.2, not just
2.5.1.

Matplotlib aside, you might want to make sure you installed the
Unicode version of wxWidgets, and reinstall it if necessary.

Josh

On Sun, Apr 13, 2008 at 3:12 PM, Gideon Simpson <grs2103@...1353...> wrote:
> I don't see any error when I run python setup.py build for matplotlib. It
> seems to identify everything it needs.
> -gideon
>
>
>
> On Apr 13, 2008, at 10:35 AM, Joshua Lippai wrote:
>
>
> > Are you sure you built pylab correctly? See if you can find something
> > suspicious in the build dialog. I had this error once a long time ago,
> > but at some point since then a rebuild of everything fixed it. In the
> > mean time, using savefig will still work even if the GUI button
> > doesn't.
> >
> > Josh
> >
> > On Sat, Apr 12, 2008 at 11:41 AM, Gideon Simpson <grs2103@...1353...> > > wrote:
> >
> > > For some reason when trying to save in PNG format on OS X 10.5.2, a
> > > window pops up with the error:
> > >
> > > Matplotlib backend_wx error
> > > cannot return std::string from Unicode object
> > >
> > >
> > > This is with the simple scipy demo at
> http://www.scipy.org/Cookbook/OptimizationDemo1
> > >
> > >
> > > Gideon Simpson
> > > Department of Applied Physics & Applied Mathematics
> > > Columbia University
> > > grs2103@...1353...
> > >
> > >
> > >
> -------------------------------------------------------------------------
> > > This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
> > > Don't miss this year's exciting event. There's still time to save $100.
> > > Use priority code J8TL2D2.
> > >
> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
> > > _______________________________________________
> > > Matplotlib-users mailing list
> > > Matplotlib-users@lists.sourceforge.net
> > > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> > >
> > >
> >
>
>

Yea, I've been using 4.0 compilers along with the Apple installation of Python. I'll try out your suggestions.
-gideon

···

On Apr 13, 2008, at 8:41 PM, Joshua Lippai wrote:

I know I had some matplotlib trouble in terms of compiling on OS X
Leopard before I changed the Makefile inside

/Library/Frameworks/Python.framework/Versions/Current/lib/python2.5/config/

If you're on an Intel Mac, try downloading the beta Apple GCC 4.2 from
http://developer.apple.com and alter the Makefile so that CC and CXX
are set to /usr/bin/gcc-4.2 and /usr/bin/g++-4.2 respectively. Also
remove the flag "-arch ppc" from both the BASEFLAGS and LDFLAGS
sections, and remove "-Wno-long-double" flag from the BASEFLAGS
section.

This assumes you're using the MacPython installation of Python and not
the standard one provided by Apple. I personally wouldn't recommend
using the standard Apple installation because a lot of modules assume
you have the Python Framework in /Library/Frameworks/ due to that
being the de facto standard set by MacPython and ActiveState Python.
In addition, the MacPython instalation provides Python 2.5.2, not just
2.5.1.

Matplotlib aside, you might want to make sure you installed the
Unicode version of wxWidgets, and reinstall it if necessary.

Josh

On Sun, Apr 13, 2008 at 3:12 PM, Gideon Simpson > <grs2103@...1353...> wrote:

I don't see any error when I run python setup.py build for matplotlib. It
seems to identify everything it needs.
-gideon

On Apr 13, 2008, at 10:35 AM, Joshua Lippai wrote:

Are you sure you built pylab correctly? See if you can find something
suspicious in the build dialog. I had this error once a long time ago,
but at some point since then a rebuild of everything fixed it. In the
mean time, using savefig will still work even if the GUI button
doesn't.

Josh

On Sat, Apr 12, 2008 at 11:41 AM, Gideon Simpson <grs2103@...1353... >>> > >> wrote:

For some reason when trying to save in PNG format on OS X 10.5.2, a
window pops up with the error:

Matplotlib backend_wx error
cannot return std::string from Unicode object

This is with the simple scipy demo at

http://www.scipy.org/Cookbook/OptimizationDemo1

Gideon Simpson
Department of Applied Physics & Applied Mathematics
Columbia University
grs2103@...1353...

-------------------------------------------------------------------------

This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.

http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Sorry I didn't chime in sooner, as I'm pretty sure i know exactly what the problem is, and I should have reported it a couple weeks ago when I found it.

Matplotlib aside, you might want to make sure you installed the
Unicode version of wxWidgets, and reinstall it if necessary.

Actually, this is backwards -- I think the OP is using the unicode version of wxPython, and that's the source of the problem. The unicode version returns a unicode object from a FileDialog for a path. MPL can't deal with a unicode filename, and thus the error:

Matplotlib backend_wx error
cannot return std::string from Unicode object

There are a couple solutions:

1) use the ansi, rather than unicode version of wxPython.

2) Patch MPL:
   a) convert the filename to a string before passing it off to MPL -- this is an bad kludge, as the Mac (and recent Windows, and Linux, and...) filesystem is unicode, and folks could have non-ansi characters in their filenames.

   b) Open the file with Python, and pass that into the MPL savefig method, instead of the filename. This is apparently slow with older MPLs, but has been fixed for good performance in SVN.

However, I think I tried this on the Mac, and it worked great, but on Windows, I didn't get errors, but didn't get valid PNGs either. I ended up going back to converting my filename to a string and passing that off to MPL.

See:
http://www.nabble.com/unicode-filenames-and-MPL.-to16318069.html#a16318069
For more discussion.

Can an MPL dev fix this, please?

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...