Pb with libpng on Mac OS (10.5 and 10.4) for tkinter installation

3 views
Skip to first unread message

sonnen

unread,
Jan 12, 2009, 8:56:28 AM1/12/09
to sage-support
Tkinter is not available on the binary distribution of Sage for Mac OS
10.5 (Intel).
As I wanted to use the TkAgg backend for matplotib I compiled Sage
from the source. However then again import Tkinter failed (even though
tk8.4 is installed as a framework). I noticed that _tkinter.so was
compiled properly, but was replaced
bu _tkinter_failed.so as import _tkinter did not work because it could
not
find symbol __cg_png_create_info_struct referenced in ImageIO and
expected
in sage-3.2.3/local/lib/libPng.dylib

I found a fix on an apple support list
http://lists.apple.com/archives/Unix-porting/2008/Sep/msg00033.html

The workaround is to rename libpng.dylib from sage and recompile
python using
sage -f python-2.5.2.p!
and matplotlib
sage -f matplotlib-0.98.3.p4
and everything seems to work.

It would be nice if this could be fixed properly, maybe by giving
another name
to libpng.dylib in the mac distribution, and the version with tkinter
included
in the binary distribution.

Eric Sonnendrucker

mabshoff

unread,
Jan 12, 2009, 9:16:20 AM1/12/09
to sage-support
On Jan 12, 5:56 am, sonnen <sonne...@gmail.com> wrote:

Hi Eric,

> Tkinter is not available on the binary distribution of Sage for Mac OS
> 10.5 (Intel).
> As I wanted to use the TkAgg backend for matplotib I compiled Sage
> from the source. However then again import Tkinter failed (even though
> tk8.4 is installed as a framework). I noticed that _tkinter.so was
> compiled properly, but was replaced
> bu _tkinter_failed.so as import _tkinter did not work because it could
> not
> find symbol __cg_png_create_info_struct referenced in ImageIO and
> expected
> in sage-3.2.3/local/lib/libPng.dylib

Yeah, this is a known issue.

> I found a fix on an apple support listhttp://lists.apple.com/archives/Unix-porting/2008/Sep/msg00033.html

This isn't a fix since it only work on case sensitive filesystems and
as long as Apple ships cases insensitive ones we are out of luck.
Other suggested workarounds like setting something via rpath or
playing games with env variables also doesn't work or breaks easily
when for example moving the Sage install.

> The workaround is to rename libpng.dylib from sage and recompile
> python using
> sage -f python-2.5.2.p!
> and matplotlib
> sage -f matplotlib-0.98.3.p4
> and everything seems to work.

I don't think it will since there are doctests that depend on "our"
libpng. It might be a 10.4 specific issue, but nonetheless we chose to
go with a dynamic libpng even though it creates a certain amount of
problems. It fixed a number of issues, but it introduced those issues
you are hitting. The real solution would probably be to get our hands
on the modifications made by Apple to libpng but AFAIK no one has
found them yet. Maybe nobody has made a serious effort to get them
either. In the end it should be possible to build tcl/tk not as
framework, but that might be some work. I haven't tried and the way it
looks right now I am not going to have time to look into this any time
soon.

> It would be nice if this could be fixed properly, maybe by giving
> another name
> to libpng.dylib in the mac distribution, and the version with tkinter
> included
> in the binary distribution.

This won't work as mentioned above. One way is to link statically, but
that provides its own set of problems.

> Eric Sonnendrucker

Cheers,

Michael

sonnen

unread,
Jan 13, 2009, 5:53:48 AM1/13/09
to sage-support
Hi Michael,

thank you for your quick answer.
I found that the xft font library used by Tk is requiring a link with
ImageIO which causes the trouble. The fix could then be to compile a
new version of Tk without the xft font library.
./configure --enable-framework --disable-xft (Tcl/Tk as a framework)
./configure --disable-xft (X11 lib)

Unfortunately there is a documented bug in python on mac when one uses
self installed Tcl/Tk libraries (http://bugs.python.org/msg74544)
One needs to fix the setup.py file in the python source, by putting
the
/System/Library underneath /Library/Frameworks in the function
detect_tkinter_darwin
(another option would be to install the X11 version of Tcl/Tk) but
then one would also
need to modify setup.py by commenting out detect_tkinter_darwin in
detect_tkinter.
In both cases, one needs to modify the Python setup.py included in the
sage distribution.
What is the best way for doing that ?

Cheers,

Eric

On 12 jan, 15:16, mabshoff <Michael.Absh...@mathematik.uni-

mabshoff

unread,
Jan 13, 2009, 6:20:48 AM1/13/09
to sage-support


On Jan 13, 2:53 am, sonnen <sonne...@gmail.com> wrote:
> Hi Michael,

Hi Eric,

> thank you for your quick answer.
> I found that the xft font library used by Tk is requiring a link with
> ImageIO which causes the trouble. The fix could then be to compile a
> new version of Tk without the xft font library.
> ./configure --enable-framework --disable-xft  (Tcl/Tk as a framework)
> ./configure --disable-xft  (X11 lib)

Ok, interesting.

> Unfortunately there is a documented bug in python on mac when one uses
> self installed Tcl/Tk libraries (http://bugs.python.org/msg74544)
> One needs to fix the setup.py file in the python source, by putting
> the
> /System/Library  underneath /Library/Frameworks in the function
> detect_tkinter_darwin
> (another option would be to install the X11 version of Tcl/Tk) but
> then one would also
> need to modify setup.py by commenting out detect_tkinter_darwin in
> detect_tkinter.
> In both cases, one needs to modify the Python setup.py included in the
> sage distribution.

Ahh, bugs, bugs, bugs :)

> What is the best way for doing that ?

Nearly all spkgs are just tar.bz2 archives. To make changes to the
python.spkg do the following:

./sage -sh
cd spkg/standard
tar xjf python-2.5.2.$FOO.spkg
cd python-2.5.2.$FOO
edit things in src as needed
./spkg-install

Let me know if you run into any trouble.

> Cheers,
>
>  Eric

Cheers,

Michael

sonnen

unread,
Jan 13, 2009, 7:42:18 AM1/13/09
to sage-support


On 13 jan, 12:20, mabshoff <Michael.Absh...@mathematik.uni-
Hi Michael

thanks a lot! Tkinter is now working fine for me and I can use
matplotlib with the TkAgg backend
For the record, here are the steps I followed to get it working on Mac
OS (10.4 and 10.5)
1) Download the Tcl/Tk sources
2) Compile the unix version (of Tcl and Tk) as follows
./configure --enable-framework --disable-xft, make, make install
3) Modify the setup.py file in the src directory of python-2.5.2.p8 by
putting
/System/Library underneath /Library/Frameworks at the top the
function detect_tkinter_darwin
4) run ./spkg-install in python-2.5.2.p8
5) reinstall matplotlib: sage -f matplotlib-0.98.3.p4

As this is the way Apple recommends to do it in the developer
documentation. I suggest that
the fix in the function detect_tkinter_darwin of the python-2.5.2.p8
setup.py gets included in the official Sage release. People needing
Tkinter on mac would then just need to have Tcl/Tk without
xft installed before compiling Sage.

Best wishes and thanks for the great job you are doing with the Sage
developers and maintainers,
Eric

William Stein

unread,
Jan 13, 2009, 9:09:25 AM1/13/09
to sage-s...@googlegroups.com
That seems harmless. This is now trac #4970:

http://trac.sagemath.org/sage_trac/ticket/4970

I'm glad it's not impossibly hard to get sage+tcl/tk working on OS X.

Willim

>
> Best wishes and thanks for the great job you are doing with the Sage
> developers and maintainers,
> Eric
>
>
> >
>



--
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org
Reply all
Reply to author
Forward
0 new messages