Python PIL and Vista/Windows 7 .. show() not working ...

David Bolen db3l.net at gmail.com
Mon Nov 30 16:37:05 EST 2009


Esmail <ebonak at gmail.com> writes:

> I dug around in the docs and found a named parameter that I can set
> when I
> call show.
>
> Definition:     im.show(self, title=None, command=None)
>
> I installed irfanview and specified it/its path in the parameter,
> but that didn't work either. It's really quite puzzling in the
> case of Vista since that's been around for quite a few years now.

But I thought everyone was sticking their fingers in their ears and
humming to try to forget Vista had been released, particularly now
that Windows 7 is out :-)

Perhaps there's an issue with the temporary file location.  I don't
have a Vista system to test on, but the show() operation writes the
image to a temporary file as returned by tempfile.mktemp(), and then
passes the name on to the external viewer.  The viewing command is
handed to os.system() with the filename embedded without any special
quoting.  So if, for example, the temporary location has spaces or
"interesting" characters, it probably won't get parsed properly.

One easy debugging step is probably to add a print just before the
os.system() call that views the image (bottom of _showxv function in
Image.py in my copy of 1.1.6).  That way at least you'll know the
exact command being used.

If that's the issue, there are various ways around it.  You could
patch PIL itself (same function) to quote the filename when it is
constructing the command.  Alternatively, the tempfile module has a
tempdir global you could set to some other temporary directory before
using the show() function (or any other code using tempfile).

-- David



More information about the Python-list mailing list