Announcement

Collapse
No announcement yet.

Problem With Python Imaging Library Showing Images

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Problem With Python Imaging Library Showing Images

    If you are running Kubuntu or another distro that uses a KDE desktop you may not be able to view your work while using the Python Imaging Library (PIL) within a Python shell using the show() method.

    I ran across this problem before but had long forgotten the solution and it isn't easy to Google a solution, so this post if for anyone having a similar problem which will probably be me again in a few months and a hardware upgrade from now. You may not experience this problem if you have eog, gqview or more unlikely xv installed and installing them may also resolve this issue. This should be a common issue for anyone running only KDE. Here is an example:

    Code:
    >>> import Image
    >>> im = Image.open("yourpic.png")
    >>> im.show()
    This module is designed to open the "yourpic.png" image with one of four viewers known by PIL. The known viewers are eog, gqview, gwenview and xv. I haven't tested eog or gqview but gwenview chokes on the temporary PIL file with the following error:

    "Gwenview cannot display documents of type application/octet-stream."

    It may be possible to fix that issue with Gwenview but I don't have the knowledge to get it to work. The problem with xv is that it is proprietary. If you don't have a problem with that it is available at no cost, but I haven't tried that either.

    What finally did work for me is going into the PIL Image.py module and changing the default list of known viewers. It is a simple fix but don't try this if you aren't comfortable with editing Python source code and sudo. These instructions are not a step by step recipe and simply installing the Eye of Gnome viewer may also work and you may prefer that method to fix this issue even if you have the skill to edit a module's source code.

    First locate the source code for the PIL module. For me it was at /usr/share/pyshared/PIL/Image.py.

    Search for "def _showxv(" you should find it on or near line 2069 in Image.py, the actual line you need to edit looks like this:

    Code:
          for cmd in ["eog", "gqview", "gwenview", "xv"]:
    Just add your preferred viewer to the front of the list, it will use the first one it finds.

    I used kuickshow but if you prefer you could also use the Imagemagick display command. Those are the only two I've tested but I'm sure there are more.

    If you know an easy way to get Gwenview to stop choking on Netpbm PPM "rawbits" image data I'd be interested.
    ---
    MyMiasma

    #2
    Re: Problem With Python Imaging Library Showing Images

    Nice post, you can add [SOLVED] to the original Subject line so people can find the solution more easily.

    By the way, that's pretty sloppy programming from whoever wrote that line in the PIL. These magic parameters should be configured in a config file. Or, if that's not possible or people are lazy to do that, they should define all the constants in some visible place at the top of the file so nobody needs to dig into the code like you needed to do. Nice find!

    Comment


      #3
      Re: Problem With Python Imaging Library Showing Images

      Thanks a lot for this useful tip. It's working for me and I have discovered kuickshow!
      Configuration:<br />Kubuntu 9.04<br />Intel Core 2 Duo E7200 - Gigabyte GA-EP45-DS3R - 4x1024 Corsair DDR2-6400 - ATI Radeon HD4850

      Comment

      Working...
      X