[Pythonmac-SIG] py2app question -- resources?

Stephen Waterbury waterbug at pangalactic.us
Tue Sep 26 21:34:46 CEST 2006


My app reads some of its core structures from a set of
RDF files.  I have been keeping the RDF files in a directory
within the distribution, but it would be okay to have them in
my app's home directory, say ~/.my_app, when the package is
installed or when the user starts it up (the latter probably
making the most sense on systems that are designed to be
multi-user), but haven't yet got either way to work with
py2app.

The new setuptools' pkg_resources API looked pretty good,
so I'm using it to pull data out of the RDF files with
'resource_stream'.  It works in my development environment
on Linux that has been configured with 'setup.py development',
and it also works on the Macintosh that way -- i.e.,
running the script in the development environment, where it
can find the RDF files.  But it doesn't work when I make
a package using py2app.

(I fudged it on mswin by having the Innosetup
installer copy the files to the user's home directory
and then finding the home directory at startup.)

py2app's '--resources' option seems like what I need,
but I can't seem to figure out the proper incantation,
because when the app starts up I immediately get an
error message that the files can't be found.

I've attached the setup.py I'm using.  Below is an
excerpt from my code that uses resource_stream, which
works fine when the files are in the place indicated.

Any suggestions?  (I did give the kb directory an
__init__.py, even though there are no modules in it, and
even tried putting the files into an __all__, but it had
no effect on py2app.)

Thanks!
Steve

-----------------------------------------------------
kbres = {'pgef' : resource_stream('pangalactic', 'meta/kb/pgef.owl'),
          'pgef_meta' : resource_stream(
                        'pangalactic', 'meta/kb/pgef_meta.owl'),
          'owl' : resource_stream('pangalactic', 'meta/kb/owl.rdf'),
          'rdf' : resource_stream('pangalactic', 'meta/kb/rdf.rdf'),
          'rdfs' : resource_stream('pangalactic', 'meta/kb/rdfs.rdf')
           }
kb = KB(kbdata=kbres)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: setup_pangalaxian.py
Type: text/x-python
Size: 4953 bytes
Desc: not available
Url : http://mail.python.org/pipermail/pythonmac-sig/attachments/20060926/f735a489/attachment.py 


More information about the Pythonmac-SIG mailing list