Re: [cx-freeze-users] Problem with PIL Image.py
Brought to you by:
atuining
From: Bob I. <bo...@re...> - 2005-03-13 23:20:46
|
On Mar 13, 2005, at 9:49, Sharrea Day wrote: > Bob Ippolito wrote: > >> On Mar 7, 2005, at 1:19 AM, Sharrea Day wrote: >> >>> I'm new to FreezePython so please bear with me. I've searched for >>> an answer to this and found a couple of workarounds that didn't work >>> for me. >>> >>> Using python-2.3.3 and FreezePython-3.0.1 I froze my app which works >>> fine before freezing - but after freezing I get an error "cannot >>> identify image file" from PIL's Image module called by ReportLab. >>> >>> I've tried importing the image plugin (import GifImagePlugin) in my >>> main python script file before freezing but still get the error. >> >> >> This is the code that py2app injects into your application's >> bootstrap when you use PIL, which monkeypatches the initialization so >> it works correctly from a packaged environment... >> >> def _recipes_pil_prescript(plugins): >> import Image >> import sys >> def init(): >> if Image._initialized >= 2: >> return >> for plugin in plugins: >> try: >> __import__(plugin, globals(), locals(), []) >> except ImportError: >> if Image.DEBUG: >> print 'Image: failed to import' >> print f, ':', sys.exc_info()[1] >> if Image.OPEN or Image.SAVE: >> Image._initialized = 2 >> Image.init = init >> >> It also automatically detects every ImagePlugin you have, and adds >> them all to the application automatically, so you don't need to do >> any explicit imports. With cx_Freeze, you would have to do that >> manually. > > Thanks for your input bob. Unfortunately I'm new to python... well > any programming actually... this is my first program. > > I tried fiddling with the PIL files to no avail and I couldn't figure > out how to manually do anything with my application's "bootstrap" (a > google search wasn't much help either). I decided to remove the image > from the invoices that ReportLab produces for now. I'll have another > go at it sometime in the future. > > Who knows, if any code sharing occurs between cx_freeze and py2app > then my problem might disappear anyway (fingers crossed). > > Even if I couldn't solve my problem your help was much appreciated. Yeah, this certainly isn't first python program stuff (unless you were using a Mac with py2app, in which case it would've worked fine). Bootstrap is just py2app terminology, I'm not sure if cx_Freeze has something similar or not. py2app runs a script full of initialization code (currently named __boot__.py) to set up the environment before it runs your main script. If cx_Freeze has nothing similar, then you would simply place the code at the top of the main script. The code above will not work unchanged from cx_Freeze, though. It would need to also have something like this: # these are hints for cx_Freeze so that the modules get included, modules not listed will not work. import GifImagePlugin, JpegImagePlugin, PngImagePlugin # and this initializes PIL with the default set of plugins that are desired _recipes_pil_prescript("GifImagePlugin JpegImagePlugin PngImagePlugin".split()) -bob |