py2app - Python: determine if running inside a .app bundle or not? -


i'm working py2app on python 2, , wondering if there's way detect code whether app running part of compiled .app file, or standalone script.

this important because of code dynamically loads .dylib file. when running natively script, code runs fine; however, when running inside .app, like:

traceback (most recent call last):   file ".../python/game/dist/main.app/contents/resources/__boot__.py", line 316, in <module>     _run()   file ".../python/game/dist/main.app/contents/resources/__boot__.py", line 311, in _run     exec(compile(source, path, 'exec'), globals(), globals())   file ".../python/game/dist/main.app/contents/resources/main.py", line 1, in <module>     import game   file "game.pyc", line 10, in <module>   file "gui.pyc", line 5, in <module>   file "audio/__init__.pyc", line 2, in <module>   file "audio/pybass.pyc", line 65, in <module>   file "ctypes/__init__.pyc", line 365, in __init__ oserror: dlopen(...python/game/dist/main.app/contents/resources/lib/python2.7/site-packages.zip/audio/libbass.dylib, 6): no suitable image found.  did find:     .../python/game/dist/main.app/contents/resources/lib/python2.7/site-packages.zip/audio/libbass.dylib: stat() failed errno=20 2013-07-15 02:50:21.146 main[10040:707] main error 

i'm thinking best way move .dylib file outside of library , resources, dynamically load there - in order need detect in code whether i'm running in .app or not, , if so, in different location library (namely, resources folder of app bundle)

help appreciated!

py2app sets sys.frozen "macosx_app" (for application bundles).

a way avoid problem use "packages" option:

setup(   ...   options={      'py2app': {         'packages': ['audio'],       }   } ) 

this includes entire "audio" package in application bundle directory instead of adding site-packages zipfile. way don't have detect whether or not you're in application bundle.


Comments