Packaging PySide applications on MacOS

Since I have been struggling to get a working Package out of my PySide application I wanted to document the way I found to make it work.

Requirements

Installing PyInstaller from SVN

  1. svn co http://svn.pyinstaller.org/trunk ~/PyInstaller
  2. ln -s ~/PyInstaller/pyinstaller /usr/bin/pyinstaller

Because of the Bug #299 [pyinstaller.org] there is a problem with PyInstaller on Mac, but there is a Patch which makes it work: Patch [groups.google.com]

With this Patched version you can start to make a spec file for PyInstaller.

Creating Spec

Here is an example that works for me (main.spec):

  1. # -*- mode: python -*-
  2. import sys, shutil
  3.  
  4. root = '/Path/to/appname'
  5.  
  6. a = Analysis(
  7.  [
  8.   os.path.join(HOMEPATH,'support/_mountzlib.py'),
  9.   os.path.join(CONFIGDIR,'support/useUnicode.py'),
  10.   'main.py'
  11.  ],
  12.  pathex=[root])
  13.  
  14. pyz = PYZ(a.pure)
  15. exe = EXE( pyz,
  16.           a.scripts,
  17.           a.binaries,
  18.           a.zipfiles,
  19.           a.datas,
  20.           name=os.path.join(root, 'dist', 'main'),
  21.           debug=False,
  22.           strip=None,
  23.           upx=True,
  24.           console=True )
  25.  
  26. version = "0.0.1"
  27.  
  28. if sys.platform.startswith("darwin"):
  29.     app = BUNDLE(exe,
  30.                  name=os.path.join(root, 'dist', 'appname.app'),
  31.                  version=version)
  32.    
  33.     shutil.copytree(
  34.         '/Library/Frameworks/QtGui.framework/Versions/Current/Resources/qt_menu.nib',
  35.         os.path.join(root, 'dist', 'appname.app', 'Contents/Resources/qt_menu.nib'))
  36.  
  37.     shutil.copy(
  38.         os.path.join(root, "res/app.icns"),
  39.         os.path.join(root, 'dist', 'appname.app', 'Contents/Resources/App.icns'))

Packaging

Now from your terminal interface go to the directory of your app and package it with this command:

  1. pyinstaller main.spec