Freetype, jpeg, zlib and the Python Imaging Library on OSX 10.5
I’ve spent the better part of a few days going through the Django guide, following along closely, and executing their code examples as I proceeded.
Predictably, things haven’t been smooth.
The biggest obstacle appeared when I hit Chapter 5: Interacting with Database Models. The book laid out a few sample models, and after making sure the database was set up, I was asked to run the following code from my django project folder:
$ python manage.py validate
The result of which was:
...Lots of errors...
...then in red:..
Error: One or more models did not validate:
books.author: "headshot": To use ImageFields, you need to install the Python Imaging Library. Get it at "http://www.pythonware.com/products/pil/":http://www.pythonware.com/products/pil/.
PIL
OK, so I head over and snag the PIL lib & attempt to set it up:
note: OSX 10.5 doesn’t come with the libraries that are necessary for the build process. Before proceeding, you’ll probably want to obtain Apple’s Xcode package and install it. (download and install Xcode 3.0) Another note: You’ll also want to have enabled your OSX root account (You can read how to do that here)
$ curl -O http://effbot.org/downloads/Imaging-1.1.6.tar.gz
$ tar xvzf Imaging-1.1.6.tar.gz
Imaging-1.1.6/README
Imaging-1.1.6/CHANGES
Imaging-1.1.6/CONTENTS
....
Imaging-1.1.6/Tk/install.txt
Imaging-1.1.6/Tk/booster.txt
Imaging-1.1.6/Tk/pilbitmap.txt
$ cd Imaging-1.1.6
$ python setup.py build_ext -i
running build_ext
--- using frameworks at /System/Library/Frameworks
--------------------------------------------------------------------
PIL 1.1.6 BUILD SUMMARY
--------------------------------------------------------------------
version 1.1.6
platform darwin 2.5.1 (r251:54863, Feb 4 2008, 21:48:13)
[GCC 4.0.1 (Apple Inc. build 5465)]
--------------------------------------------------------------------
--- TKINTER support ok
*** JPEG support not available
*** ZLIB (PNG/ZIP) support not available
*** FREETYPE2 support not available
--------------------------------------------------------------------
...
Oh. That’s no good. An imaging library without imaging or type support. Useful.
Luckily, we’re not invalids, and the PIL README yielded resources for obtaining the required libs. We need to install them and take note of their lib paths.
Freetype
$ curl -O http://download.savannah.gnu.org/releases/freetype/freetype-2.1.10.tar.bz2
$ tar --use-compress-program bzip2 -xvf freetype-2.1.10.tar.bz2
$ cd freetype-2.1.10
$ ./configure
cd builds/unix; ./configure
...lots of files...
$ make
...several seconds of compilation...
$ sudo make install
Password: *YOUR OSX ROOT PASS*
If all went well, your Freetype lib should be installed at /usr/local/lib.
Jpeg
$ curl -O http://www.ijg.org/files/jpegsrc.v6b.tar.gz
$ tar xvzf jpegsrc.v6b.tar.gz
$ cd jpeg-6b
$ ./configure
$ make
$ make install
If all goes well, your Jpeg lib can be found in your jpeg-6b directory (to find the path type pwd while in the jpeg-6b directory).
zlib / PNG support
$ curl -O http://www.zlib.net/zlib-1.2.3.tar.gz
$ tar xvzf zlib-1.2.3.tar.gz
$ cd zlib-1.2.3
$ ./configure
$ make
$ sudo make install
Password: *YOUR OSX ROOT PASS*
Again, if all is well, your zlib lib can be found in your zlib directory (and again, type pwd while in the zlib directory to find the path)
Edit PIL’s setup.py
Head back over to your PIL directory & open up setup.py in a text editor. Around line 37 you should see a set of vars ending in _ROOT, like so:
FREETYPE_ROOT = None
JPEG_ROOT = None
TIFF_ROOT = None
ZLIB_ROOT = None
TCL_ROOT = None
Change None to the appropriate paths, like so:
FREETYPE_ROOT = "/usr/local/lib"
JPEG_ROOT = "/your/path/to/jpeg-6b"
TIFF_ROOT = None
ZLIB_ROOT = "/your/path/to/zlib-1.2.3"
TCL_ROOT = None
Nailed. Save setup.py and get back to the shell.
PIL, again
Let’s try that install again:
$ python setup.py build_ext -i
running build_ext
--- using frameworks at /System/Library/Frameworks
--------------------------------------------------------------------
PIL 1.1.6 BUILD SUMMARY
--------------------------------------------------------------------
version 1.1.6
platform darwin 2.5.1 (r251:54863, Feb 4 2008, 21:48:13)
[GCC 4.0.1 (Apple Inc. build 5465)]
--------------------------------------------------------------------
--- TKINTER support ok
--- JPEG support ok
--- ZLIB (PNG/ZIP) support ok
--- FREETYPE2 support ok
--------------------------------------------------------------------
To check the build, run the selftest.py script.
Support OK, eh? Sounds good to me.
$ sudo python setup.py install
running install
running build
running build_py
...
running install_egg_info
Writing /Library/Python/2.5/site-packages/PIL/PIL-1.1.6-py2.5.egg-info
creating /Library/Python/2.5/site-packages/PIL.pth
$
Success! Let’s try validating our models again. Get back over to your Djando project folder, and execute the validation command again:
$ python manage.py validate
...
0 errors found
Yay.
Comments
Comments closed for this article.