オープンデータとプログラミング

Tag Archive for pip

pipでPIL(画像ライブラリ)のインストールがうまくいかない場合の解決方法(メモ)

python

pipでPIL(画像ライブラリ)をインストールしようとしてうまくいかなかった場合の対処方法に関するメモです。

PILは古い(2009年開発終了)のでPillowの使用をお勧めします。PIL向けのソースはほぼそのままで動くと思います。
環境:
python 2.7.11
CentOS release 6.7 (Final)

いろいろネットの情報を参考にしてpipを実行しましたがエラーがでてうまくいきません。

$pip install PIL --allow-external PIL --allow-unverified PIL

エラー内容は以下のとおりです。

DEPRECATION: --allow-external has been deprecated and will be removed in the future. Due to changes in the repository protocol, it no longer has any effect.
DEPRECATION: --allow-unverified has been deprecated and will be removed in the future. Due to changes in the repository protocol, it no longer has any effect.
Collecting PIL
  Could not find a version that satisfies the requirement PIL (from versions: )
No matching distribution found for PIL

このような場合は、以下のサイトからソースをダウンロードしてコンパイルします。

最新版をDLします。

Python Imaging Library 1.1.7 Source Kit (all platforms) (November 15, 2009)

適当な場所に解凍したら、ディレクトリに降りてsetup.pyを実行。

$python setup.py install

途中、freetypeのヘッダまわりでエラーになる場合があります。

_imagingft.c:73:31: error: freetype/fterrors.h: そのようなファイルやディレクトリはありません
_imagingft.c:78: error: expected expression before ‘static’
_imagingft.c: In function ‘getfont’:
_imagingft.c:132: error: ‘library’ undeclared (first use in this function)
_imagingft.c:132: error: (Each undeclared identifier is reported only once
_imagingft.c:132: error: for each function it appears in.)
_imagingft.c:144: 警告: passing argument 1 of ‘FT_New_Face’ from incompatible pointer type

この解決方法は、シンボリックリンクを作成してあげればOKです。
※freetypeのインストール場所は環境によって異なる場合があるかもしれませんのでよく確認してください

ln -s /usr/include/freetype2/freetype /usr/local/include/freetype

シンボリックリンクを作成したら再度、setup.pyを実行。

$python setup.py install

以上で完了です。