Creating a Mac app from python/panda

I am trying to create a distributable Mac application from a Panda project. I have been trying to use py2app, but thus far haven’t gotten very far. I have read over the forum posts which go over using py2exe on the Windows side and have made some progress by adapting their methods, but I’m still stuck.

In addition to this, the game I’m working on also uses pyGame, but I’m just trying to take this one step at a time as there seems to be a pretty well documented way to use py2app with pyGame. Thus far I have managed to get an app created, but it fails upon startup with the error (from the Mac console)

The setup file I am using with py2app looks like this:

"""
This is a setup.py script generated by py2applet

Usage:
    python setup.py py2app
"""

from setuptools import setup
import py2app
import os

PANDA_DIR = '/Applications/Panda3D/1.6.0/' 

APP = ['main.py']
DATA_FILES = []
OPTIONS = {'argv_emulation': True}

setup(
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],


packages = [
        'direct',
        'direct.directbase',
        'direct.showbase',
        'direct.interval',
        'direct.actor',
        'direct.gui',
        'direct.task',
        'direct.controls',
        'direct.directnotify',
        'direct.directtools',
        'direct.directutil',
        'direct.fsm',
        'direct.cluster',
        'direct.particles',
        'direct.tkpanels',
        'direct.tkwidgets',
        'direct.directdevices',
        'direct.distributed',
        'pandac',
        ],
package_dir = {
        'direct' : os.path.join(PANDA_DIR, 'lib/direct'),
        'direct.directbase' : os.path.join(PANDA_DIR, 'lib/direct/directbase'),
        'direct.showbase' : os.path.join(PANDA_DIR, 'lib/direct/showbase'),
        'direct.interval' : os.path.join(PANDA_DIR, 'lib/direct/interval'),
        'direct.actor' : os.path.join(PANDA_DIR, 'lib/direct/actor'),
        'direct.gui' : os.path.join(PANDA_DIR, 'lib/direct/gui'),
        'direct.task' : os.path.join(PANDA_DIR, 'lib/direct/task'),
        'direct.control' : os.path.join(PANDA_DIR, 'lib/direct/control'),
        'direct.directnotify' : os.path.join(PANDA_DIR, 'lib/direct/directnotify'),
        'direct.directtools' : os.path.join(PANDA_DIR, 'lib/direct/directtools'),
        'direct.directutil' : os.path.join(PANDA_DIR, 'lib/direct/directutil'),
        'direct.fsm' : os.path.join(PANDA_DIR, 'lib/direct/fsm'),
        'direct.cluster' : os.path.join(PANDA_DIR, 'lib/direct/cluster'),
        'direct.particles' : os.path.join(PANDA_DIR, 'lib/direct/particles'),
        'direct.tkpanels' : os.path.join(PANDA_DIR, 'lib/direct/tkpanels'),
        'direct.tkwidgets' : os.path.join(PANDA_DIR, 'lib/direct/tkwidgets'),
        'direct.directdevices' : os.path.join(PANDA_DIR, 'lib/direct/directdevices'),
        'direct.distributed' : os.path.join(PANDA_DIR, 'lib/direct/distributed'),
        'pandac' : os.path.join(PANDA_DIR, 'lib/pandac'),
        },
data_files = [
    ( 'etc', [ 'etc/Config.prc', ] ),
             ]
       ) 

Note that the comment at the top says that the file was generated by py2applet, and while the base of the file was, it was heavily modified by following posts concerning py2exe.

I know I’m on unstable ground just working with Panda on a Mac, and am probably pushing it to get an app, but any help here would be great as my team would like to be able to release a Mac version of our game along with the Windows version. I am using pro-rsoft’s version of 1.6 from http://152.10.254.215/~pro-rsoft/Panda3D-1.6.0-pre.dmg with MacPython 2.5.4

Thanks

The relevant error message in all of that is this line:

ImportError: DLL loader cannot find libpandaexpress. 

So, I’m guessing that libpandaexpress.so and/or libpandaexpress.dylib didn’t get bundled into your app. Probably all of the other libraries are missing as well.

I don’t know anything about py2app, but maybe there must be some way to tell it to add these files?

If it did add those files, then maybe the problem is that you need to tell OSX where to find them. You might need to set the environment variable DYLD_LIBRARY_PATH to an appropriate path, for instance “.”, before starting the executable. Again, I don’t know how this might be done in py2app, but surely there’s a way to do it.

David

I don’t know the details since I’ve not done this yet myself, but I do have experience using py2app to bundle Python programs into Mac applications (plus I’m going to have to figure this one out too eventually, since I’m using Panda on a Mac too.)

I can say this: with other applications I’ve bundled (ie. not Panda apps) I’ve sometimes had to add certain files to the app manually. I’m sure there’s some way by adjusting the setup script in py2app to add more files to be included, but it was simpler to simply manually copy those files in.

The important thing to realize is that a Mac app is in fact a folder that is hidden away by default. That is, a Mac app is actually a folder named something.app, and OSX responds differently to double-clicking on a folder named .app versus other folders. To get access to the insides of a .app folder, right-click on the icon and choose Show Contents.

Beyond that I wish you luck with the specifics. Off the top of my head I would guess you need to copy any missing libraries into the “resources” directory in the .app, but I’m not sure.