Nasty Zope & Python Imaging Library name collision

Fredrik Lundh effbot at telia.com
Sat Apr 15 07:27:38 EDT 2000


miles <miles at caddr.com> wrote:
> I've finally traced a mysterious failure in some Zope external methods
> I've been working on to a module name collision between Zope.  In a
> nutshell, they both contain an 'ImageFile' module and the wrong one
> gets loaded.
>
> This is essentially what my external method does:
>
> import Image
> i = Image.open(filename.jpg)
> i = i.resize((x,y))
> i.save(newfilename.jpg)
>
> This eventually results in the construction of a Jpeg image object which
> is supposed to derive from ImageFile.ImageFile from the Imaging library.
> Sadly, the __init__ method from Zope's ImageFile module is called instead,
> which promptly goes berserk.
>
> Is there anything I can do to fix this?  How do people do deal with these
> kinds of problems in general?  It seems to be very easy to inadvertently
> collide with another module.  Perl avoids this by allowing arbitrarily
nested
> modules.  For example, in this case I'd have Zope::ImageFile and
> Imaging::ImageFile and everything would be roses.

assuming you have PIL 1.0, just make sure you've installed
all the PIL files in a directory named PIL, and then do:

    from PIL import Image

instead of "import Image".

if you have an older version, you may have to add an
__init__.py file to the PIL directory, and explicitly import
format handlers for the file formats you want to use (e.g.
import PIL.JpegImagePlugin, PIL.GifImagePlugin)

</F>






More information about the Python-list mailing list