Package a Python Qt (PySide) application for Windows (.exe)
That's fairly easy to package a Python Qt (PySide) application for Windows (and even easier on Linux with cxfreeze).
Let see two different ways of doing so.
Contents
1. py2exe
Pros
- Easy
- Support multiple binaries
Cons
- Might miss some dependencies
Download
Py2Exe Website
There are binaries for both win32 and win64.
Basic setup
basic_setup.py
from distutils.core import setup
import py2exe
setup(
windows = ['pysideApp1.py','pysideApp2.py'],
options = {
"py2exe" : {
"includes" : ['sys', 'tempfile', 'zipfile', 'mmap', 'encodings',
'json', 'hashlib', 'datetime', 'struct',
'os', 'time', 'random', 'math', 'xmlrpclib', 'Crypto']
}
}
)
Compile
$ python basic_setup.py py2exe
That's it!
Look in your "dist" folder and you should have your application
2. PyInstaller
Pros
- Seems to detect the required libraries much better
Cons
- Last stable version (1.5.1 as today) does not support multiple binaries
- Need a little more config
Download
PyInstaller Website
No need to install, just extract somewhere.
PySide setup
pyside.spec
import os
a = Analysis(
[os.path.join(HOMEPATH,'support\\_mountzlib.py')
, os.path.join(HOMEPATH,'support\\useUnicode.py')
, os.path.normpath(os.path.join(currentDir, 'main.py'))
, os.path.normpath(os.path.join(currentDir, 'importantLib.py'))
# add the files you want PyInstaller to analyse the "import" statements
# to detect the libraries to include
],
pathex=['C:\\Python27\\pyinstaller-1.5.1']
)
pyz = PYZ(a.pure)
exe = EXE(pyz,
a.scripts,
exclude_binaries=1,
name=os.path.join('build\\pyi.win32\\build_output', 'your_application.exe'),
debug=False,
strip=False,
upx=True,
console=False )
coll = COLLECT( exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name=os.path.join('dist', 'dist_output'))
Compile
Move to your pyinstaller.py location and run:
$ python pyinstaller.py "C:\path\to\pyside.spec"
That's it!
Look in your "dist_output" folder and you should have your application
Postface
Both methods work fine.
The output folder with PyInstaller is a little bigger (~10MB, whereas the one with py2exe is ~8MB).
However, it seems to include more libraries, even though I didn't manually specified any specific library, I just gave the 2 main py files of my program, so maybe more reliable.
Recent posts
- Run Django from a VM and access it from the host
- Package a Python Qt (PySide) application for Windows (.exe)
- Install Google Chrome Web Browser in Ubuntu 11.10 Oneiric Ocelot
- Python Qt4 recipe: QSingleApplication (PySide)
- 20 years of Linux
- Python VS Ruby through a concrete GUI example (Qt)
- Reasonable people
- Quickly build smartphone applications (iPhone, Android, WP7, BB, Symbian) with Rhomobile Rhodes
- Could not find /etc/localtime, unable to determine host timezone
- Ruby on Rails: the best web programming framework?
Home
Accueil
ホーム