Fix PIL 1.1.6 installation from sources under debian

Today I found a bug in kupu integration in Plone. I prepared a patch and I tried to reinstall plonenext environment. But this time it fails to install on the PIL egg.

The PIL egg is very dependant to your architecure. It depends of libjpeg, tkinter (tcl/tk), and some other libraries. I’m working with a Debian unstable with 3 versions of tcl/tk for various programs: 8.3, 8.4 and 8.5.

The errors was the following:

getting distribution for ‘PIL’.
libImaging/Effects.c:210: warning: ‘perlin_init’ defined but not used
libImaging/Geometry.c:236: warning: ‘quadratic_transform’ defined but not used
libImaging/Quant.c:311: warning: ‘test_sorted’ defined but not used
libImaging/Quant.c:676: warning: ‘checkContained’ defined but not used
libImaging/QuantHash.c:136: warning: ‘_hashtable_test’ defined but not used
_imagingtk.c:20:16: error: tk.h: Aucun fichier ou répertoire de ce type
_imagingtk.c:23: error: expected ‘)’ before ‘*’ token
_imagingtk.c:31: error: expected specifier-qualifier-list before ‘Tcl_Interp’
_imagingtk.c: In function ‘_tkinit’:
_imagingtk.c:37: error: ‘Tcl_Interp’ undeclared (first use in this function)
_imagingtk.c:37: error: (Each undeclared identifier is reported only once
_imagingtk.c:37: error: for each function it appears in.)
_imagingtk.c:37: error: ‘interp’ undeclared (first use in this function)
_imagingtk.c:45: error: expected expression before ‘)’ token
_imagingtk.c:51: error: ‘TkappObject’ has no member named ‘interp’
_imagingtk.c:55: warning: implicit declaration of function ‘TkImaging_Init’
error: Setup script exited with error: command ‘gcc’ failed with exit status 1

All development libraries was installed, but the installer cannot find /usr/include/tk.h. There are /usr/include/tcl8.3/tk.h, /usr/include/tcl8.4/tk.h, /usr/include/tcl8.5/tk.h. Then I wrote the little patch below for the file:

—    (révision 460)
+++    (copie de travail)
@@ -199,6 +199,9 @@
add_directory(library_dirs, « /usr/lib »)
add_directory(include_dirs, « /usr/include »)

+        if os.path.isfile(os.path.join(‘/usr/include’, ‘tcl’+TCL_VERSION,’tk.h’)):
+            add_directory(include_dirs, os.path.join(‘/usr/include’, ‘tcl’+TCL_VERSION))
# insert new dirs *before* default libs, to avoid conflicts
# between Python PYD stub libs and real libraries

I hope this patch is generic enough to be merged in the next Imaging release. Waiting this next release, I’m searching for a method to patch an egg before it is compiled by zc.buildout.

Update: this patch is included in PIL 1.1.7beta1

Recommandation lors de l’installation de python sur un plateforme linux 64 bits

L’installation des modules python demande une précaution: être sur d’utiliser les version 64bits des bibliothèques C sous peine d’avoir de drôles d’erreurs absolument intraçables.

La solution est de déclarer le chemin vers /usr/lib64 explicitement pour lors des l’édition des liens:
export LD_LIBRARY_PATH=/usr/lib64

Exemple avec PIL

Version installé avec libjpeg-devel_32, zlib-devel_64 et freetype-devel_64. A la fin de l’installation on vous dit ça:

version 1.1.6
platform linux2 2.4.4 (#2, Jul 17 2007, 10:05:58)
[GCC 4.1.2 20070115 (prerelease) (SUSE Linux)]
*** TKINTER support not available
--- JPEG support ok
*** ZLIB (PNG/ZIP) support not available
*** FREETYPE2 support not available

Le support jpeg est le seul installé… du coup l’intervenant installe les versions devel_32 pour les autres.

Vous noterez qu’il n’y a aucune référence au 64bits dans les infos sur la plateforme.

version 1.1.6
platform linux2 2.4.4 (#2, Jul 17 2007, 10:05:58)
[GCC 4.1.2 20070115 (prerelease) (SUSE Linux)]
*** TKINTER support not available
--- JPEG support ok
--- ZLIB (PNG/ZIP) support ok
--- FREETYPE2 support ok

toto@webtest:/tmp/Imaging-1.1.6> /usr/local/bin/python2.4


Failure in example: _info("Images/lena.jpg"))

from line #24 of selftest.testimage

Exception raised:

Traceback (most recent call last):

File "./", line 499, in _run_examples_inner

exec compile(source, "<string>", "single") in globs

File "<string>", line 1, in ?

File "./", line 22, in _info


File "PIL/", line 180, in load

d = Image._getdecoder(self.mode, d, a, self.decoderconfig)

File "PIL/", line 375, in _getdecoder

raise IOError("decoder %s not available" % decoder_name)

IOError: decoder jpeg not available

1 items had failures:

1 of 57 in selftest.testimage

***Test Failed*** 1 failures.

*** 1 tests of 57 failed.

Là, l’intervenant commence à se ronger les ongles et à chercher l’entrée de la 4ème dimension.

Il fouille le net et fini par tomber sur un message d’espoir:

Évidemmement il n’y a aucune référence à ce point dans la documentation de PIL.

Donc, il faut installer les versions -devel_64 des bibliothèques et déclarer LD_LIBRARY_PATH dans votre shell:

toto@webtest:/tmp/Imaging-1.1.6> /usr/local/bin/python2.4
57 tests passed.

Que du bonheur.