[Pythonmac-SIG] py2app and PythonCard

Kevin Altis altis at semi-retired.com
Mon Oct 25 19:52:03 CEST 2004


On Oct 25, 2004, at 10:16 AM, Bob Ippolito wrote:

>
> On Oct 25, 2004, at 12:44, Chris Barker wrote:
>
>> Bob Ippolito wrote:
>>> On Oct 25, 2004, at 12:21, Chris Barker wrote:
>>>> Bob Ippolito wrote:
>>>>> This is sort of a bug in py2app.  You are using software that uses 
>>>>> PIL,  but you do not have PIL installed.
>>>>
>>>> Huh? does py2app use PIL? why?
>>> No.  His software uses PIL (indirectly via PythonCard, it seems), 
>>> py2app detected this and tried to include PIL, but PIL was not 
>>> present.  svn trunk has been changed such that now py2app only tries 
>>> to use recipes for packages that are actually present (a change to 
>>> the recipes, not anything in py2app's core).
>>
>> Ah, I see. So this is really the same problem we can get with 
>> packages that conditionally import stuff. If you're not using it, 
>> Py2app doesn't know that. In fact, PIL is (or was, last I checked), 
>> whenever I've tried to Py2exe an app that uses PIL, I get all if 
>> tkinter too, even though I wasn't using it. It sounds like you're 
>> solving at least half the problem.
>
> If you py2exe an app that uses PIL you'll probably have an application 
> that doesn't work.  One of the things that makes py2app more generally 
> useful than py2exe is that it includes special exceptions, called 
> recipes, that allow additional things to happen when certain packages 
> are detected.  In cases like PIL or docutils, plugins need to be 
> detected and added to the zip, or else they won't work.  py2app 
> includes recipes that do these things.  Also, in PIL, it eliminates 
> the implicit dependency on Tkinter (by means of FixTk), so if you 
> don't use Tkinter elsewhere, then it won't be included.
>
> py2app includes everything it sees, even if you don't think you're 
> using it.  If you know you're not using a particular module or 
> package, and you see that it is getting included anyway, then simply 
> exclude it explicitly.  It's not very hard to do.  I would say that a 
> whole lot more than half the problem is solved by py2app.
>

Sorry, I'm late to the the party. I was at the Seattle coding sprint 
last weekend and I'm just now catching up on email. I haven't tried 
py2app yet as last week I was wrapping up the PythonCard 0.8.1 release. 
There are bundlebuilder scripts for a variety of samples and tools:

     PythonCard/samples/minimalStandalone/macbuild.py
     PythonCard/tools/codeEditor/macbuild.py
     PythonCard/tools/findfiles/macbuild.py

I'm hoping to convert them to py2app, though I have no idea what is 
involved yet.

Both PythonCard/graphic.py and PythonCard/components/bitmapcanvas.py 
have conditional imports for PIL, and bitmapcanvas.py has one for 
Numeric as well.

try:
     import Image
     # necessary to avoid name collision with Image class
     from Image import fromstring
     PIL_FOUND = True
except ImportError:
     PIL_FOUND = False

try:
     from Numeric import ArrayType
     NUMERIC_FOUND = True
except ImportError:
     NUMERIC_FOUND = False

In the short term, you could just comment out the imports and force the 
FOUND constants to False and that will avoid the conditional import. 
The readme.txt gives the py2exe option to exclude libraries you don't 
want included in your standalone.

"""
Use the following command-line to build the minimal.exe file.
    python setup.py py2exe --excludes=Image
"""

I don't know if py2app has something similar, but it would be nice for 
the apps that know they aren't using particular libraries like PIL 
which are imported optionally. The reason the imports are there in the 
first place, is that PythonCard supports drawing and converting PIL and 
Numeric arrays.

ka



More information about the Pythonmac-SIG mailing list