[IMAGE-SIG] [FYI & Q] Problems installing PIL and spectrogram

Harald Singer singer@itl.atr.co.jp
Tue, 10 Mar 1998 16:19:57 +0900


Some minor (and major) problems when installing PIL with
	PIL0.3a3, Python1.5, Linux2.0.32, Tk8.0p2 (+Japanese Patch 3)

[1] spell miss?

from Types import IntType, StringType, TupleType

Shouldn't this be types? I couldn't find any Types.py in Python1.5.


   Then type (assuming a standard shell):

	$ cd test
	$ PYTHONPATH=..:../Lib ; export PYTHONPATH
	$ python

	>>> import _imaging
	>>> import Image

I couldn't find any test directory. I then did
	mkdir test; cd test

cp _imagingmodule.so /usr/local/lib/python1.5/site-packages
cp -r Imaging/Lib /usr/local/lib/python1.5/Imaging
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python1.5/Imaging

It seemed to work (don't know what I should expect, though).

I then followed the instructions to recompile tkinter

gcc -g -O2 -I./../Include -I.. -DHAVE_CONFIG_H  -DWITH_APPINIT -I/usr/local/include -c ./tkImaging.c
./tkImaging.c:44: Imaging.h: No such file or directory

I then looked at the Modules/Setup file more closely. It is already prepared for PIL!
I uncommented the PIL line in Modules/Setup and 
	mv ../Extensions/Imaging-0.3a3 ../Extensions/Imaging
However, then I get

gcc -g -O2 -I./../Include -I.. -DHAVE_CONFIG_H  -DWITH_APPINIT -I/usr/local/include -DWITH_PIL -I../Extensions/Imaging/libImaging -c ./tkImaging.c
./tkImaging.c: In function `PyImagingPhoto':
./tkImaging.c:76: warning: passing arg 1 of `Tk_FindPhoto' from incompatible pointer type
./tkImaging.c:76: too few arguments to function `Tk_FindPhoto'
make: *** [tkImaging.o] Error 1

Looking at /usr/local/lib/tk.h

#define TK_MAJOR_VERSION   8
#define TK_MINOR_VERSION   0
#define TK_RELEASE_LEVEL   2

#define TK_VERSION "8.0"
#define TK_PATCH_LEVEL "8.0p2"


EXTERN Tk_PhotoHandle	Tk_FindPhoto _ANSI_ARGS_((Tcl_Interp *interp,
			    char *imageName));

I then changed in tkImaging.c
    photo = Tk_FindPhoto(argv[1]);
    photo = Tk_FindPhoto(interp,argv[1]);

and it compiled/linked! The following also worked

bash$ cd Extension/Imaging/Scripts
bash$ python1.5 viewer.py ../Images/lena.jpg


[4] now my major problem: I am trying to plot a spectrogram
and I get this error:

  File "specgram.py", line 300, in __init__
    photo = ImageTk.PhotoImage(image)
  File "/usr/local/lib/python1.5/Imaging/ImageTk.py", line 65, in __init__
    mode = image.palette.mode
AttributeError: attribute-less object

	if hasattr(image, "mode") and hasattr(image, "size"):
	    # got an image instead of a mode
	    mode = image.mode
            if mode == "P":
                # palette mapped data
==>             mode = image.palette.mode
	    size = image.size
	    kw["width"], kw["height"] = size
            mode = image
	    image = None

If I change the offending line to
		mode = 'RGB'

it somehow works, at least this works
	photo = ImageTk.PhotoImage(image)

but this just shows a blank buttong

BTW, to create this image I did something like 

    # create a PIL image of palette type
    image = Image.new("P",(fftorder/2,yyy.shape[0]))
    image.im.putpalette("RGB", Colormap2Palette())

(if it is of interest I can post the complete source code for creating
 a colorful spectrogram, but I would rather find a fix before doing that)
Harald Singer, ATR ITL, tel +81-7749-5-1389   singer@itl.atr.co.jp

IMAGE-SIG - SIG on Image Processing with Python

send messages to: image-sig@python.org
administrivia to: image-sig-request@python.org