Problems compiling matplotlib under OS X

The easiest way to describe this is to repeat the info that's been
posted into the "macpython" mailing list--sorry if you've already
seen it. According to one of the people who helped me on the
macpython list, the problem I'm having is
likely caused by matplotlib using a custom method of finding
Tcl/Tk headers, rather than by a Python/OS X interaction problem,
which is why I'm bringing the topic over to this list.

Many thanks for any help you can offer!

Here's what has gone before, consisting of questions from me and
answers from other people. I've done some editing to shorten things up.

ยทยทยท

I'm attempting to compile matplotlib, and get messages saying that
it can't find the headers for Tcl/Tk. They exist, they just happen to
be in the Frameworks directories for Tcl and for Tk. I know I can
get this to work by hacking (setting up path variables, putting symbolic
links in directories, or some such), but aside from the fact that that's
a pain and ugly, it doesn't solve the more general problem; if header
files are supposed to be in Frameworks directories (for example, I
found my Tk header files in /Library/Frameworks/Tk.framework/Headers),
what is the best way to set up OS X so that they will be available to link
against?

Short answer: Whatever you're trying to build is (incorrectly) not using tclConfig.sh (they should allow the user to choose which one, but should default to /usr/lib/tclConfig.sh I guess). This is equivalent to not using distutils. It probably won't be a problem in the Mac OS X future however, because...

Apple's latest strategy for unixy stuff (at least for Python) seems to be a hybrid approach that should please almost anyone:
  (1) the actual dylib lives in /usr/lib and has a mach-o id pointing to /usr/lib
  (2) the framework has symlinks to /usr/lib for its dylib
  (3) the headers live in the framework
  (4) /usr/include has appropriate symlinks into the framework

[I can say this without breaking NDA because Apple has publicly released their sources for Python in Darwin 8.0.0b1]

After reading Bob's message, I looked into /usr/lib and found that while
it contained a tclConfig.sh, there was no tkConfig.sh. A search of the
file system revealed a tkConfig.sh in /Library/Framewords/Tk.framework, so
I copied it there.

While I suspect this was a Good Thing To Do, it still hasn't solved
the problem of matplotlib's setup.py not being able to find the tcl/tk
headers. Here's my attempt at building and the resultant message:

  ken% python setup.py build
  GTKAgg requires pygtk
  cannot find tcl/tk headers. giving up.

The message about "GTKAgg" is expected and should be ignored. Attempting
a "python setup.py -v build" gave exactly the same error messages. Unfortunately
the error message about the header, while to the point, isn't terribly helpful :slight_smile:

matplotlib is packaged using distutil, and presumably distutil isn't getting
the info it needs to figure out where the headers are. I've started reading
about distutil, but am a novice at it (and it's a fairly involved package, as
well), so if others could offer suggestions as to how to track down/fix this
problem, it would be a real help.

distutils is only good at finding Python's compiler/linker settings and Python's headers.
matplotlib has custom code to find Tcl/Tk in its setup.py, and that custom code is not doing the right thing.