How do I make .app from Python include image files

py2app, python, wxpython

Solution

The easiest way to include resources is to specify them as `data_files` in your `setup.py`

from setuptools import setup

APP = ['app.py']
DATA_FILES = [('', ['images'])]
OPTIONS = {'argv_emulation': True}

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

`<app.app>/Contents/Resources` will be the current directory and resource root for all data. This will place the `images/` directory of your project within the resource root.

If you only wanted to include specific files from your `images/` directory you can tell it how to map:

DATA_FILES = [
    ('images', ['images/picture.jpg', 'images/picture2.png']),
    ('images/icons', ['images/icons/ico1.ico'])
]

Or you can get fancier and say "only include all jpegs from my image dir":

from glob import glob
...
DATA_FILES = [
    ('images', glob('images/*.jpg')),
]

Problem

I want to make a .app file from my Python source. My Python source is wxPython and has 11 image files (.png , size is 32x32) Making the .app is a success, but it does not include my image files, it just shows the error message `no bitmap handler for types 50 defined.` Details... `Can't load image from file...` Even in the same directory it is still showing this error message. I'm using `py2app`, `python 2.7`, and `wxPython` on MacOSX 10.6.7 How can I make a .app with my image files?

Original source