Packaging PySide applications on MacOS

From Qt Wiki
Jump to: navigation, search
This article may require cleanup to meet the Qt Wiki's quality standards. Reason: Auto-imported from ExpressionEngine.
Please improve this article if you can. Remove the {{cleanup}} tag and add this page to Updated pages list after it's clean.

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

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

Because of the Bug #299 there is a problem with PyInstaller on Mac, but there is a Patch which makes it work: Patch

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):

#-*- mode: python -*-
import sys, shutil
 
root = '/Path/to/appname'
 
a = Analysis(
 [
 os.path.join(HOMEPATH,'support/_mountzlib.py'),
 os.path.join(CONFIGDIR,'support/useUnicode.py'),
 'main.py'
 ],
 pathex=[root])
 
pyz = PYZ (a.pure)
exe = EXE( pyz,
 a.scripts,
 a.binaries,
 a.zipfiles,
 a.datas,
 name=os.path.join(root, 'dist', 'main'),
 debug=False,
 strip=None,
 upx=True,
 console=True )
 
version = "0.0.1"
 
if sys.platform.startswith("darwin"):
 app = BUNDLE (exe,
                 name=os.path.join(root, 'dist', 'appname.app'),
 version=version)
 
shutil.copytree(
 '/Library/Frameworks/QtGui.framework/Versions/Current/Resources/qt_menu.nib',
 os.path.join(root, 'dist', 'appname.app', 'Contents/Resources/qt_menu.nib'))
 
shutil.copy(
 os.path.join(root, "res/app.icns"),
 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:

pyinstaller main.spec