I'm having problems with PIL that I am surprised that no one has run into
yet.  In a nutshell, my application, when unfrozen with pyinstaller, will
read PNGs, JPEGs, TIFFs, TGAs, and other file formats with no problem.
 When frozen, some formats are ok (PNG, JPEG, BMP) while other formats now
fail to read (TIFF, TGA).  I get exactly this error:
http://www.mail-archive.com/[email protected]/msg01167.html

It looks like the hiddenimports part of PIL is being handled correctly in
pyinstaller; it looks like:

HIDDEN IMPORTS ['Hdf5StubImagePlugin', 'SgiImagePlugin', 'PpmImagePlugin',
'PalmImagePlugin', 'ArgImagePlugin', 'GifImagePlugin', 'MspImagePlugin',
'JpegImagePlugin', 'FpxImagePlugin', 'PdfImagePlugin', 'GbrImagePlugin',
'EpsImagePlugin', 'WmfImagePlugin', 'ImImagePlugin', 'PsdImagePlugin',
'BufrStubImagePlugin', 'SpiderImagePlugin', 'BmpImagePlugin',
'XVThumbImagePlugin', 'FitsStubImagePlugin', 'ImtImagePlugin',
'CurImagePlugin', 'MpegImagePlugin', 'TiffImagePlugin', 'PixarImagePlugin',
'XpmImagePlugin', 'TgaImagePlugin', 'SunImagePlugin',
'GribStubImagePlugin', 'IcoImagePlugin', 'PcxImagePlugin',
'IptcImagePlugin', 'XbmImagePlugin', 'PngImagePlugin', 'MicImagePlugin',
'McIdasImagePlugin','IcnsImagePlugin', 'DcxImagePlugin', 'PcdImagePlugin',
'FliImagePlugin']

But the problem is, that it doesn't really matter if the modules are
packaged up or not.  In PIL, all of the plugins are imported by the
following code in Image.py:

def init():
    "Load all file format drivers."

    global _initialized
    if _initialized >= 2:
        return 0

    visited = {}

    directories = sys.path

    try:
        directories = directories + [os.path.dirname(__file__)]
    except NameError:
        pass

    # only check directories (including current, if present in the path)
    for directory in filter(isDirectory, directories):
        fullpath = os.path.abspath(directory)
        if visited.has_key(fullpath):
            continue
        for file in os.listdir(directory):
            if file[-14:] == "ImagePlugin.py":
                f, e = os.path.splitext(file)
                try:
                    sys.path.insert(0, directory)
                    try:
                        __import__(f, globals(), locals(), [])
                    finally:
                        del sys.path[0]
                except ImportError:
                    if DEBUG:
                        print "Image: failed to import",
                        print f, ":", sys.exc_value
        visited[fullpath] = None

    if OPEN or SAVE:
        _initialized = 2
        return 1


As you can see, the *ImagePlugin.py files must exist in-the-clear in any of
the directories that it happens to check.  I did verify that if I copy all
of the plugin files to my apps (frozen) directory, I can immediately start
reading TIFFs and TGAs again.

So, I'm not sure what to do in order to make sure that the *ImagePlugin.py
files exist, other than to just straight copy them over as data files
within Pyinstaller; surely there is a correct way of handling this problem.
 Also, this means that onefile distros will not be able to ever use all of
the image formats that PIL supports.  Is there a way to fake PIL into
looking inside the frozen .exe file for these modules?

There are obviously a couple of things I can do to hack a solution (either
copy the files as data files, or just explicitly importing each plugin that
i need somewhere will work, I think).  But I figured that someone else
would run into this sooner or later.


-- 
Daniel Hyams
[email protected]

-- 
You received this message because you are subscribed to the Google Groups 
"PyInstaller" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pyinstaller?hl=en.

Reply via email to