Hatena::ブログ(Diary)

Bstyle = LOlita + Gothic 4th Trial このページをアンテナに追加 RSSフィード Twitter

2011-02-01

PythonのPILをMacOS Xでつかったときに怒られる。 01:06

先日Pycon mini JPにいった時に、blockdiagというナイスなソフトを知りました。

ので使ってみようと思い、pipからインストールすると怒られます。

reki$:pip install blockdiag
(略)
reki$: blockdiag -o test.png test.diag
Traceback (most recent call last):
  File "/usr/local/bin/blockdiag", line 8, in <module>
    load_entry_point('blockdiag==0.6.6', 'console_scripts', 'blockdiag')()
  File "/Library/Python/2.6/site-packages/blockdiag/blockdiag.py", line 421, in main
    draw.draw()
  File "/Library/Python/2.6/site-packages/blockdiag/DiagramDraw.py", line 96, in draw
    self.node(node, **kwargs)
  File "/Library/Python/2.6/site-packages/blockdiag/DiagramDraw.py", line 204, in node
    font=self.font, badgeFill=self.badgeFill)
  File "/Library/Python/2.6/site-packages/blockdiag/noderenderer/box.py", line 24, in render_node
    lineSpacing=metrix.lineSpacing)
  File "/Library/Python/2.6/site-packages/blockdiag/ImageDrawEx.py", line 264, in textarea
    lines = TextFolder(box, string, scale=self.scale_ratio, **kwargs)
  File "/Library/Python/2.6/site-packages/blockdiag/utils/PILTextFolder.py", line 14, in __init__
    self.ttfont = ImageFont.truetype(font, fontsize)
  File "/Library/Python/2.6/site-packages/PIL/ImageFont.py", line 218, in truetype
    return FreeTypeFont(filename, size, index, encoding)
  File "/Library/Python/2.6/site-packages/PIL/ImageFont.py", line 134, in __init__
    self.font = core.getfont(file, size, index, encoding)
  File "/Library/Python/2.6/site-packages/PIL/ImageFont.py", line 34, in __getattr__
    raise ImportError("The _imagingft C module is not installed")
ImportError: The _imagingft C module is not installed

しらべると、PIL(Python Image Library)の1.1.6をいれるといいらしいのでいれてみる

reki:$pip uninstall pil
reki:$pip install pil==1.1.6
 Could not find a version that satisfies the requirement pil==1.1.6 (from versions: )
No distributions matching the version for pil==1.1.6
Storing complete log in /Users/marth/.pip/pip.log

ないっていわれたのでこまった。

Windowsだとバイナリエディターとか荒技つかうんだけど、Macなので情報なし。

でもいっかいPILをいれてみると……

    --------------------------------------------------------------------
    PIL 1.1.7 SETUP SUMMARY
    --------------------------------------------------------------------
    version       1.1.7
    platform      darwin 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
                  [GCC 4.2.1 (Apple Inc. build 5646)]
    --------------------------------------------------------------------
    --- TKINTER support available
    *** JPEG support not available
    --- ZLIB (PNG/ZIP) support available
    *** FREETYPE2 support not available
    *** LITTLECMS support not available
    --------------------------------------------------------------------
    To add a missing option, make sure you have the required
    library, and set the corresponding ROOT variable in the
    setup.py script.

FREETYPE2がサポートされていない!!これが原因だ!!!

というわけでhomebrewでいれてみると(MacPorts嫌い)

reki$brew install freetype2
Error: No available formula for freetype2

ないっていわれたよ(´Д`;)

でしょうがないのでつくったw

https://github.com/yuuna/homebrew/blob/freetype/Library/Formula/freetype2.rb


require 'formula'

class Freetype2 <Formula
  url 'http://sourceforge.net/projects/freetype/files/freetype2/2.4.4/freetype-2.4.4.tar.gz/download'
  homepage 'http://freetype.sourceforge.net/index2.html'
  md5 '9273efacffb683483e58a9e113efae9f'
  version '2.4.4'

  # depends_on 'cmake'

  def install
    system "./configure", "--disable-debug", "--disable-dependency-tracking",
                          "--prefix=#{prefix}"
    # system "cmake . #{std_cmake_parameters}"
    system "make install"
  end
end

これを/usr/local/Library/Formula/にいれてFreetypeをいれてpipから再度インストール(pullリクエストおくってるのでそのうちmergeされるかも)

reki:$ sudo brew install freetype2
==> Downloading http://sourceforge.net/projects/freetype/files/freetype2/2.4.4/freetype-2.4.4.tar.gz/download
######################################################################## 100.0%
==> ./configure --disable-debug --disable-dependency-tracking --prefix=/usr/local/Cellar/freetype2/2.4.4
==> make install
/usr/local/Cellar/freetype2/2.4.4: 54 files, 2.5M, built in 16 seconds
reki:$ pip install pil

さすがMacProはやいっ、じゃなくて。

ログの最後をみると

    --------------------------------------------------------------------
    PIL 1.1.7 SETUP SUMMARY
    --------------------------------------------------------------------
    version       1.1.7
    platform      darwin 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
                  [GCC 4.2.1 (Apple Inc. build 5646)]
    --------------------------------------------------------------------
    --- TKINTER support available
    *** JPEG support not available
    --- ZLIB (PNG/ZIP) support available
    --- FREETYPE2 support available
    *** LITTLECMS support not available
    --------------------------------------------------------------------
    To add a missing option, make sure you have the required
    library, and set the corresponding ROOT variable in the
    setup.py script.

無事サポートされたみたい。

というわけで無事うごきました。

よくみるとjpegもサポートされていなかったのでlibjpegをいれて再度いれなおしました。

やっぱりhomebrewだね、homebrewヽ(´ー`)ノ