[Pythonmac-SIG] Trying to make an app

Steven Palm n9yty at n9yty.com
Thu Oct 7 04:07:50 CEST 2004


On Oct 6, 2004, at 4:06 PM, Bob Ippolito wrote:
> find BitPim.app -name "*.so" -or -name "*.dylib" -exec strip {} \;

  That didn't change the bundle size, so obviously that's not it. Maybe  
it's not a huge deal, I'll come back to this one later. ;-)  It's  
obviously putting more in the bundle because when I make a compressed  
disk image (as I did after bundlebuilder as well), the size is almost  
twice as big (14MB as opposed to ~7MB before).

>>>  or you're including too many packages explicitly without reason.
>>
>>  Not sure, most of the code is Roger's.
>
> I was referring to the setup.py

  Here is my new base setup.py:

     from distutils.core import setup
     import py2app
     import string
     packageroot="."
     name = "BitPim"
     iconfile = "bitpim.icns"
     v=getsubs()
     data_files=[]
     includes=[]
     includePackages=[]
     verstr = "%s-%s" % (v['NAME'], v['VERSION'])
     for dir,files in resources():
         for file in files:
             fname = os.path.basename(file)
             data_files.append( os.path.join(dir, fname))
     coms=glob.glob("com_*.py")
     for c in coms:
         includes.append(c[:-3])
     plist = dict(
         CFBundleIconFile            = iconfile,
         CFBundleName                = name,
         CFBundleShortVersionString  = verstr,
         CFBundleGetInfoString       = '-'.join([name, verstr]),
         CFBundleExecutable          = name,
         CFBundleIdentifier          = 'net.sourceforge.bitpim',
     )
     opts = dict(py2app=dict(
                  iconfile=iconfile,
                  plist=plist,
                  includes=includes
                  ))
     app = [ dict(
                  plist=plist,
                  script="bp.py",
                  ),]
     setup( data_files = [ ('resources', data_files) ], options = opts,   
app = ap
p,)

  If I turn on "optimize=2", I get this failure when building:

Traceback (most recent call last):
   File "setup.py", line 415, in ?
     macbuild()
   File "setup.py", line 394, in macbuild
     setup( data_files = [ ('resources', data_files) ], options = opts,   
app = app,)
   File  
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3/distutils/core.py", line 149, in setup
     dist.run_commands()
   File  
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3/distutils/dist.py", line 907, in run_commands
     self.run_command(cmd)
   File  
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3/distutils/dist.py", line 927, in run_command
     cmd_obj.run()
   File  
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3/site-packages/py2app/build_app.py", line 214, in run
     self._run()
   File  
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3/site-packages/py2app/build_app.py", line 310, in _run
     self.create_binaries(new_py_files, pkgdirs, extensions, mm)
   File  
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3/site-packages/py2app/build_app.py", line 373, in  
create_binaries
     dry_run=self.dry_run)
   File  
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3/site-packages/py2app/util.py", line 117, in byte_compile
     spawn(cmd, verbose=verbose, dry_run=dry_run)
NameError: global name 'spawn' is not defined

> dist_dir isn't what you think it is.. I'm using the same semantics as  
> py2exe (which I don't particularly like, so that may change).  In  
> order to change the resultant executable destination you have to do:
>
> setup(
> 	app = [
> 		dict(script="myscript.py", dest_base="./dist"),
> 	],
> )

I couldn't get dest_base to work, I just do this:

     os.system('mv ./BitPim.app ./dist');

>  BitPim.app/Contents/Resources/Python/lib-dynload/native/usb
>
>>  One more issue is that some package parts are loaded dynamically,  
>> such as this:
>>
>> dlg=CommPortDialog(self,  
>> __import__(self.phonemodels[self.phonebox.GetValue()]),  
>> defaultport=self.commbox.GetValue(), sashposition=p)
>>
>>  It complains that it cannot find the module referenced by  
>> self.phonemodels[self.phonebox.GetValue()]).
>>
>>  For bundlebuilder, I was doing this:
>>
>>     coms=glob.glob("com_*.py")
>>     for c in coms:
>>         myapp.includePackages.append(c[:-3])
>>
>>  For py2app, I was just using passing a build includePackages list in  
>> via the "packages" element in the options dict. I cannot find the  
>> comm_* files anywhere in the generated bundle, in the  
>> site_packages.zip file or outside of it. They are included as:
>>
>>     options = dict(p2app=dict(
>>                  optimize=2,
>>                  dist_dir="./dist/",
>>                  compress=1,
>>                  packages=includePackages,
>>                  includes=data_files,
>>                  iconfile=iconfile,
>>                  plist=plist))
>>
>>  where includePackages is built above.
>
> There are several problems with this:
> There is a typo in the options dict.. it should be:
> dict(py2app=dict(

  That fixed that. ;-)

>>  Also, the dependencies checker seems to be missing the fact that  
>> libusb must be included... I see it coming up with a libusb.so, but  
>> that's just the SWWIG generated stub, I think, in bundlebuilder I had  
>> to include the dylib itself.
>
> Can you show me the output of:
> otool -Lv  
> BitPim.app/Contents/Resources/Python/lib-dynload/native/usb/_libusb.so

_libusb.so:
         /System/Library/Frameworks/Python.framework/Versions/2.3/Python  
(compatibility version 2.3.0, current version 2.3.0)
         time stamp 1092103224 Mon Aug  9 21:00:24 2004
         /usr/lib/libSystem.B.dylib (compatibility version 1.0.0,  
current version 71.1.1)
         time stamp 1085619810 Wed May 26 20:03:30 2004

I guess when that was built it compiled in what it needed from libusb,  
I had both a static and shared version of that available.

> Where is this usb package and how do I build it so I can see what it's  
> doing?

The library is at libusb.sourceforge.net, but obviously you don't have  
to spend much time on it, as I was mistaken about it being needed.

> btw - svn trunk includes the encodings package instead of including it  
> as a package.. so that gets rid of a bunch of files and should save  
> 1mb or so (before compression).

  I get this when using the trunk version:

Traceback (most recent call last):
   File  
"/usr/local/src/bitpim/bitpim/dist/BitPim.app/Contents/Resources/ 
__boot__.py", line 26, in ?
     _run('bp.py')
   File  
"/usr/local/src/bitpim/bitpim/dist/BitPim.app/Contents/Resources/ 
__boot__.py", line 23, in _run
     execfile(os.path.join(base, 'Python', script), globals(), globals())
   File  
"/usr/local/src/bitpim/bitpim/dist/BitPim.app/Contents/Resources/ 
Python/bp.py", line 75, in ?
     import gui
   File "gui.pyc", line 23, in ?
   File "wx/__init__.pyc", line 42, in ?
   File "wx/_core.pyc", line 4, in ?
   File "wx/_core_.pyc", line 18, in ?
   File "wx/_core_.pyc", line 15, in __load
ImportError:  
'/usr/local/src/bitpim/bitpim/dist/BitPim.app/Contents/Resources/ 
Python/lib-dynload/wx/_core_.so' not found
2004-10-06 20:51:28.492 BitPim[1121] BitPim Error
2004-10-06 20:51:28.492 BitPim[1121] An unexpected error has occurred  
during execution of the main script

ImportError:  
'/usr/local/src/bitpim/bitpim/dist/BitPim.app/Contents/Resources/ 
Python/lib-dynload/wx/_core_.so' not found

  Finally, back to a real basic question...

  Is there a way in the script which contains the setup() call to  
actually have it build the bundle without having to specifically  
provide the py2app parameter on the command line? BitPim uses a  
"makedist.py" file to build for all three platforms, and in the past  
you would just issue "python makedist.py" to build it, it would be nice  
if you didn't have to give the Mac additional parameters.  I see Roger  
is using py2exe to build the Windows version, but he has a sub-config  
file and is spawning a subshell from makedist.py with a new python  
interpreter to run it. That seems ugly. ;-)

  Thanks!




More information about the Pythonmac-SIG mailing list