Python Imaging Library(PIL)インストール

移転しました。

集合知プログラミング3章やってるのだが、Python Imaging Library が必要。
ってことで、Leopardにインストールしてみる。

$ wget http://effbot.org/downloads/Imaging-1.1.6.tar.gz
$ tar zxvf Imaging-1.1.6.tar.gz
$ cd Imaging-1.1.6
$ sudo python setup.py install

よいはいったので、サンプルプログラムを動かすと以下でエラー
以下のようなエラーが発生。

>>> DIR = '/hoge/'
>>> blognames,words,data=readfile(DIR + 'blogdata.txt')
>>> clust=hcluster(data)
>>> printclust(clust,labels=blognames)
>>> drawdendrogram(clust,blognames,jpeg=DIR + 'blogclust.jpg')
Traceback (most recent call last):
  File "/Users/matsukazetakashi/work/eclipseWrk/python/cluster/src/clusters.py", line 143, in <module>
    drawdendrogram(clust,blognames,jpeg=DIR + 'blogclust.jpg')
  File "/Users/matsukazetakashi/work/eclipseWrk/python/cluster/src/clusters.py", line 115, in drawdendrogram
    img.save(jpeg,'JPEG')
  File "/Library/Python/2.5/site-packages/PIL/Image.py", line 1405, in save
    save_handler(self, fp, filename)
  File "/Library/Python/2.5/site-packages/PIL/JpegImagePlugin.py", line 409, in _save
    ImageFile._save(im, fp, [("jpeg", (0,0)+im.size, 0, rawmode)])
  File "/Library/Python/2.5/site-packages/PIL/ImageFile.py", line 487, in _save
    e = Image._getencoder(im.mode, e, a, im.encoderconfig)
  File "/Library/Python/2.5/site-packages/PIL/Image.py", line 391, in _getencoder
    raise IOError("encoder %s not available" % encoder_name)
IOError: encoder jpeg not available

なんかjpegのライブラリ入れなきゃらしい。
ここみると、ソースからいれてるからソースでいってみるか

$ wget http://www.ijg.org/files/jpegsrc.v6b.tar.gz
$ tar zxvf jpegsrc.v6b.tar.gz
$ cd jpeg-6b
$ ./configure
$ make
$ make install-lib
/usr/bin/install -c -m 644 jconfig.h /usr/local/include/jconfig.h
install: /usr/local/include/jconfig.h: No such file or directory
make: *** [install-headers] Error 71

でもエラーがでちゃったよ。

うむぅ〜と、じゃぁportでいれてみるか。

$ sudo port install jpeg
--->  Fetching jpeg
--->  Attempting to fetch jpegsrc.v6b.tar.gz from http://www.ijg.org/files
--->  Attempting to fetch droppatch.tar.gz from http://sylvana.net/jpegcrop/
--->  Verifying checksum(s) for jpeg
--->  Extracting jpeg
--->  Applying patches to jpeg
--->  Configuring jpeg
--->  Building jpeg with target all
--->  Staging jpeg into destroot
--->  Installing jpeg 6b_2
--->  Activating jpeg 6b_2
--->  Cleaning jpeg

でも、おんなじ。
IOError: encoder jpeg not available
でちまうなぁ
sudo port install build
ってうつと、freetype2なるものが入ってないとでている。

--------------------------------------------------------------------
PIL 1.1.6 BUILD SUMMARY
--------------------------------------------------------------------
version       1.1.6
platform      darwin 2.5.1 (r251:54863, Apr 15 2008, 22:57:26)
              [GCC 4.0.1 (Apple Inc. build 5465)]
--------------------------------------------------------------------
--- TKINTER support ok
--- JPEG support ok
--- ZLIB (PNG/ZIP) support ok
*** FREETYPE2 support not available

なので、freetypeを入れて、再度PILインストール

sudo port install freetype
cd ~/Imaging-1.1.6
sudo python install setup.py install

その後実行したらやっとJPEGはきだした。
えがったえがった。