Matplotlib with native OSX port of GTK

Hi, folks!

I am trying to compile matplotlib-0.98.3 on OSX 10.5.5. with support
for the native port of GTK-2.0 (www.gtk-osx.org). I am doing this
because the official egg gives an error when my GUIs try to create a
canvas using GTK (with all renderers: GDK, Agg or Cairo). I assume the
official egg was compiled without support for GTK on OSX.
I compiled GTK-2.0 and PyGTK using code and instructions from Imendio,
and it all works fine. The apps I developed on a Ubuintu system run
fine on OSX, except for the matplotlib part.
So, all the libraries and headers are installed in the default
folders. However, when I try to build matplotlib I get the following
error:

macproctp8:matplotlib-0.98.3 ctp8$ python setup.py build

···

============================================================================
BUILDING MATPLOTLIB
            matplotlib: 0.98.3
                python: 2.5.1 (r251:54863, Apr 15 2008, 22:57:26) [GCC
                        4.0.1 (Apple Inc. build 5465)]
              platform: darwin

REQUIRED DEPENDENCIES
                 numpy: 1.3.0.dev5934
             freetype2: found, but unknown version (no pkg-config)

OPTIONAL BACKEND DEPENDENCIES
                libpng: 1.2.32
               Tkinter: Tkinter: 50704, Tk: 8.4, Tcl: 8.4
              wxPython: 2.8.4.0
                        * WxAgg extension not required for wxPython >= 2.8
                  Gtk+: gtk+: 2.15.0, glib: 2.19.1, pygtk: 2.13.1,
                        pygobject: 2.15.5
                        * Could not find Gtk+ headers in any of
                        * '/usr/include', '/usr/X11R6/include', '.'
                    Qt: no
                   Qt4: no
                 Cairo: 1.4.12

OPTIONAL DATE/TIMEZONE DEPENDENCIES
              datetime: present, version unknown
              dateutil: present, version unknown
/Library/Python/2.5/site-packages/pytz-2008g-py2.5.egg/pytz/__init__.py:32:
UserWarning: Module dateutil was already imported from
/Library/Python/2.5/site-packages/dateutil-1.2-py2.4.egg/dateutil/__init__.pyc,
but /Library/Python/2.5/site-packages/matplotlib-0.98.3-py2.5-macosx-10.3.egg
is being added to sys.path
/Library/Python/2.5/site-packages/pytz-2008g-py2.5.egg/pytz/__init__.py:32:
UserWarning: Module pytz was already imported from
/Library/Python/2.5/site-packages/pytz-2008g-py2.5.egg/pytz/__init__.py,
but /Library/Python/2.5/site-packages/matplotlib-0.98.3-py2.5-macosx-10.3.egg
is being added to sys.path
                  pytz: 2008g

OPTIONAL USETEX DEPENDENCIES
                dvipng: 1.11
           ghostscript: 8.62
                 latex: 3.1415926

EXPERIMENTAL CONFIG PACKAGE DEPENDENCIES
             configobj: matplotlib will provide
      enthought.traits: no

[Edit setup.cfg to suppress the above messages]

running build
running build_py
copying lib/matplotlib/mpl-data/matplotlibrc ->
build/lib.macosx-10.5-i386-2.5/matplotlib/mpl-data
copying lib/matplotlib/mpl-data/matplotlib.conf ->
build/lib.macosx-10.5-i386-2.5/matplotlib/mpl-data
running build_ext
building 'matplotlib.backends._backend_gdk' extension
gcc -fno-strict-aliasing -Wno-long-double -no-cpp-precomp
-mno-fused-madd -fno-common -dynamic -DNDEBUG -g -Os -Wall
-Wstrict-prototypes -DMACOSX -I/usr/include/ffi -DENABLE_DTRACE -arch
i386 -arch ppc -pipe
-I/Library/Python/2.5/site-packages/numpy-1.3.0.dev5934-py2.5-macosx-10.3-i386.egg/numpy/core/include
-I/usr/include -I/usr/X11R6/include -I. -I/usr/include
-I/usr/X11R6/include -I.
-I/System/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5
-c src/backend_gdk.c -o
build/temp.macosx-10.5-i386-2.5/src/backend_gdk.o
In file included from src/backend_gdk.c:9:
/usr/include/pygtk/pygtk.h:6:23: error: pygobject.h: No such file or directory
/usr/include/pygtk/pygtk.h:8:21: error: gtk/gtk.h: No such file or directory
In file included from src/backend_gdk.c:9:
/usr/include/pygtk/pygtk.h:14: error: syntax error before 'atom'
/usr/include/pygtk/pygtk.h:17: error: syntax error before '*' token
/usr/include/pygtk/pygtk.h:18: error: syntax error before '*' token
/usr/include/pygtk/pygtk.h:19: error: syntax error before '}' token
/usr/include/pygtk/pygtk.h:24: error: syntax error before 'gchar'
src/backend_gdk.c: In function 'pixbuf_get_pixels_array':
src/backend_gdk.c:28: error: 'PyGObject' undeclared (first use in this function)
src/backend_gdk.c:28: error: (Each undeclared identifier is reported only once
src/backend_gdk.c:28: error: for each function it appears in.)
src/backend_gdk.c:28: error: 'py_pixbuf' undeclared (first use in this function)
src/backend_gdk.c:29: error: 'GdkPixbuf' undeclared (first use in this function)
src/backend_gdk.c:29: error: 'gdk_pixbuf' undeclared (first use in
this function)
src/backend_gdk.c:37: warning: implicit declaration of function 'GDK_PIXBUF'
src/backend_gdk.c:43: warning: implicit declaration of function
'gdk_pixbuf_get_height'
src/backend_gdk.c:44: warning: implicit declaration of function
'gdk_pixbuf_get_width'
src/backend_gdk.c:45: warning: implicit declaration of function
'gdk_pixbuf_get_has_alpha'
src/backend_gdk.c:48: warning: implicit declaration of function
'gdk_pixbuf_get_pixels'
src/backend_gdk.c:48: warning: passing argument 2 of '*(PyArray_API +
272u)' from incompatible pointer type
src/backend_gdk.c:53: warning: implicit declaration of function
'gdk_pixbuf_get_rowstride'
In file included from src/backend_gdk.c:9:
/usr/include/pygtk/pygtk.h:6:23: error: pygobject.h: No such file or directory
/usr/include/pygtk/pygtk.h:8:21: error: gtk/gtk.h: No such file or directory
In file included from src/backend_gdk.c:9:
/usr/include/pygtk/pygtk.h:14: error: syntax error before 'atom'
/usr/include/pygtk/pygtk.h:17: error: syntax error before '*' token
src/backend_gdk.c: In function
'init_backend_gdk':/usr/include/pygtk/pygtk.h:18: error: syntax error
before '*' token

src/backend_gdk.c:72: error: 'G_STMT_START' undeclared (first use in
this function)
src/backend_gdk.c:72: error: syntax error before '{'
token/usr/include/pygtk/pygtk.h:19: error: syntax error before '}'
token

src/backend_gdk.c:72: error: 'pygtk' undeclared (first use in this
function)/usr/include/pygtk/pygtk.h:24: error: syntax error before
'gchar'

src/backend_gdk.c: In function 'pixbuf_get_pixels_array':
src/backend_gdk.c:28: error: 'PyGObject' undeclared (first use in this function)
src/backend_gdk.c: At top level:src/backend_gdk.c:28: error: (Each
undeclared identifier is reported only once

src/backend_gdk.c:72: warning: type defaults to 'int' in declaration
of 'G_STMT_END'src/backend_gdk.c:28: error: for each function it
appears in.)

src/backend_gdk.c:72: warning: data definition has no type or storage
classsrc/backend_gdk.c:28: error: 'py_pixbuf' undeclared (first use in
this function)

src/backend_gdk.c:74: warning: type defaults to 'int' in declaration
of 'mod'src/backend_gdk.c:29: error: 'GdkPixbuf' undeclared (first use
in this function)

src/backend_gdk.c:29: error: 'gdk_pixbuf' undeclared (first use in
this function)
src/backend_gdk.c:74: warning: initialization makes integer from
pointer without a cast
src/backend_gdk.c:74: error: initializer element is not constant
src/backend_gdk.c:74: warning: data definition has no type or storage class
src/backend_gdk.c:75: warning: type defaults to 'int' in declaration
of '_PyGdkPixbuf_Type'
src/backend_gdk.c:75: error: conflicting types for '_PyGdkPixbuf_Type'
src/backend_gdk.c:37: warning: implicit declaration of function 'GDK_PIXBUF'
src/backend_gdk.c:12: error: previous declaration of
'_PyGdkPixbuf_Type' was here
src/backend_gdk.c:43: warning: implicit declaration of function
'gdk_pixbuf_get_height'src/backend_gdk.c:75: warning: passing argument
1 of 'PyObject_GetAttrString' makes pointer from integer without a
cast

src/backend_gdk.c:75: warning: initialization makes integer from
pointer without a castsrc/backend_gdk.c:44: warning: implicit
declaration of function 'gdk_pixbuf_get_width'

src/backend_gdk.c:75: error: initializer element is not constant
src/backend_gdk.c:45: warning: implicit declaration of function
'gdk_pixbuf_get_has_alpha'
src/backend_gdk.c:75: warning: data definition has no type or storage class
src/backend_gdk.c:76: error: syntax error before '}' token
src/backend_gdk.c:48: warning: implicit declaration of function
'gdk_pixbuf_get_pixels'
src/backend_gdk.c:48: warning: passing argument 2 of '*(PyArray_API +
272u)' from incompatible pointer type
src/backend_gdk.c:53: warning: implicit declaration of function
'gdk_pixbuf_get_rowstride'
src/backend_gdk.c: In function 'init_backend_gdk':
src/backend_gdk.c:72: error: 'G_STMT_START' undeclared (first use in
this function)
src/backend_gdk.c:72: error: syntax error before '{' token
src/backend_gdk.c:72: error: 'pygtk' undeclared (first use in this function)
src/backend_gdk.c: At top level:
src/backend_gdk.c:72: warning: type defaults to 'int' in declaration
of 'G_STMT_END'
src/backend_gdk.c:72: warning: data definition has no type or storage class
src/backend_gdk.c:74: warning: type defaults to 'int' in declaration of 'mod'
src/backend_gdk.c:74: warning: initialization makes integer from
pointer without a cast
src/backend_gdk.c:74: error: initializer element is not constant
src/backend_gdk.c:74: warning: data definition has no type or storage class
src/backend_gdk.c:75: warning: type defaults to 'int' in declaration
of '_PyGdkPixbuf_Type'
src/backend_gdk.c:75: error: conflicting types for '_PyGdkPixbuf_Type'
src/backend_gdk.c:12: error: previous declaration of
'_PyGdkPixbuf_Type' was here
src/backend_gdk.c:75: warning: passing argument 1 of
'PyObject_GetAttrString' makes pointer from integer without a cast
src/backend_gdk.c:75: warning: initialization makes integer from
pointer without a cast
src/backend_gdk.c:75: error: initializer element is not constant
src/backend_gdk.c:75: warning: data definition has no type or storage class
src/backend_gdk.c:76: error: syntax error before '}' token
lipo: can't open input file:
/var/folders/3+/3+xlC3-AFbmK3q3TEvQ0gU+++TI/-Tmp-//ccRSEFSq.out (No
such file or directory)
error: command 'gcc' failed with exit status 1

However, gtk.h and pygtk.h are in the folders where I believe they
should be (/usr/include/gtk-2.0/gtk and /usr/include/pygtk-2.0/pygtk).
I ran throught the code of check_for_gtk included in setupext.py, and
the only thing I found out of order was that the line
get_pkgconfig(module, 'pygtk-2.0 gtk+-2.0') should read
get_pkgconfig(module, 'pygtk-2.0 gtk-2.0'), as the installation folder
of GTK is gtk-2.0 and not gtk+-2.0. However, I changed this line and
got exactly the same error.

Has anyone successfully compiled matplotlib with support for the
native port of GTK for OSX? Could somenoe help me getting it compiled?

Thanks in advance,
--
Marcus Vinicius Eiffle Duarte
eiffleduarte@...287...
Niterói, RJ, Brasil

The error indicates the mpl build process is not finding your pygtk or
gtk headers. Typically, you need to set your PKG_CONFIG_PATH to the
directory where the *.pc config files are, and these will tell mpl how
to include the headers and link to the libs. So you should also have
pkg-config installed. There are some additional details here:
http://ipython.scipy.org/moin/Py4Science/InstallationOSX -- scroll
down to the "matplotlib" section.

JDH

···

On Mon, Nov 10, 2008 at 6:00 AM, Marcus Vinicius Eiffle Duarte <eiffleduarte@...287...> wrote:

So, all the libraries and headers are installed in the default
folders. However, when I try to build matplotlib I get the following
error:
In file included from src/backend_gdk.c:9:
/usr/include/pygtk/pygtk.h:6:23: error: pygobject.h: No such file or directory
/usr/include/pygtk/pygtk.h:8:21: error: gtk/gtk.h: No such file or directory
In file included from src/backend_gdk.c:9: