Deploying a PyQt app using py2exe

For future reference this exercise was done on Windows 8.1 with Python(x,y) and MS C++ 2008 Redistributable Package installed (though py2exe still couldn’t find MSVCR90.DLL):

In the same folder have three files like in the TestPyQtGUIApp archive.

The contents is:

Created on Sat Mar 05 11:37:02 2016

@author: e1z

import sys

from PyQt4 import QtCore, QtGui, uic
from PyQt4.QtCore import SIGNAL, SLOT

class MyGUIApp(QtGui.QApplication):
  def __init__(self):
    QtGui.QApplication.__init__(self, sys.argv)
    self.connect(self, SIGNAL("lastWindowClosed()"), self, SLOT("quit()")) = uic.loadUi("myAppUI.ui")
if __name__ == "__main__":

The contents is:

#!/usr/bin/env python

from distutils.core import setup
import py2exe

setup(windows=[{"script": ''}],
          "py2exe": {
              "bundle_files": 1,
              "compressed": True,
              "dll_excludes": ["MSVCP90.dll"],
              "includes": ["sip"],

Open a command prompt in the folder and run:

python py2exe

The py2exe scripts are going to take over and quite verbosely indicate what they are doing. Once the scripts are done cd into the dist subfolder and run the .exe file (the GUI does nothing other than show it is running).

If you get an error message about invalid syntax in C:\Python27\Lib\site-packages\PyQt4\uic\port_v3 go to the folder where port_v3 is located and rename the file to The port_v3 is for Python3 scripts … and some are questioning its inclusion into Python2 packages.

If you are using matplotlib packages you will need to add matplotlib specific snippets to the file as seen here.


Leave a Reply

Your email address will not be published. Required fields are marked *