Mac Python Applications and Exceptions
When wrapping up Python applications to graphically run in Mac OS X, one problem is that informative exception messages are lost. Here's a way to log them.
1 Wrapping Up Python Applications for Mac OS X
By that, I mean for instance using the py2app tool and run something along the lines of:
py2applet-2.7 MyApp.py
This will stupendously well work for applications written both with PyQt and PySide. Note that you will need to suffix the script with .py
and that it's a good idea to already give it a first uppercase letter to give the application a name with the right style.
Giving it an icon with --iconfile
has never worked for me, neither with PNG, nor with .icns
. Once you have the application generated, it's easier to open your icon image in Preview, copy the image and paste it into the icon area in Get Info.
2 Exceptions
Interestingly, unhandled exceptions in wrapped up in a Mac OS X applications won't make your whole program crash. But you won't see them either. One clean workaround is to log them instead:
def excepthook(type, value, tback):
logging.error('Line %d, %s: %s', tback.tb_lineno, type, value)
sys.__excepthook__(type, value, tback)
sys.excepthook = excepthook