Sunday, June 03, 2012

Building ReportLab on OS X with Homebrew and Freetype support

Long time, too lazy to blog. Don't ask. Moving on, I've been trying to set up my MacBook Pro as a development box for a while. Since the house I'm in is largely using Python, I've set up both virtualenv and virtualenvwrapper with the latest 2.7 Python (Lion comes with 2.7.1, latest as at the time of writing is 2.7.3), pip, distribute and whatnot.
One of the packages I wanted to install is ReportLab. Unfortunately, it kept building without Freetype support, so TrueType support was unavailable. This wasn't acceptable, so I started looking for ways to build it with FreeType support in.
According to this, I would have to download and build FreeType separately. That would not do (because I was being lazy, plus, I already had FreeType installed by Apple — I'd already tried to run brew install freetype, and Homebrew warned me that FreeType already comes with Lion in /usr/X11/include and /usr/X11/lib.
Initially, I tried adding the respective include and library paths in setup.cfg. Didn't work. Eventually, after trying seriously to grok the evil that is distutils code, I found that there is a class called inc_lib_dirs, and in its implementation of __call__(), it checks the platform, and makes a lot of calls to aDir(), setting either an include path (first argument uppercase 'I', no quotes) or a library path (first argument uppercase 'L'; again, without the quotes). I simply added new lines for the appropriate include/library, saved and ran python build. This worked, so I ran python install. Too tired to test with code. Hope it works for you.

Update: This post talks about building PIL on Snow Leopard with FreeType2 support, but the instructions also work for ReportLab. The tl;dr version is:
  1. download PIL (or ReportLab) source package
  2. unpack it
  3. change directory into the package folder
  4. create a new file called with the contents: FREETYPE_ROOT = "<freetype library path>", "<freetype header path>"
  5. run python build (or install)
Following these instructions, I was able to get PIL and ReportLab installed into my virtualenv.

1 comment:

dalembertian said...

Thanks for the post, it did put me in the right direction - but I'm only getting it to work by changing the actual to include the needed X11 dirs.

I could not make it work, though, by using this extra file. In fact, I don't understand its purpose - is it a standard name that should seek for? I couldn't find any documentation for it...