Distributing your application on Windows

Creating self-contained applications on Windows is quite straight-forward but you need to make sure than you have all of the correct software installed before you start.

Python and PyQt

Please ensure that you have installed the following versions of Python and PyQt as it can not be guaranteed that the rest of the instructions will work with earlier or later versions:

If the above links are broken try going to the download pages on each site:

Add Python to your path

We will need to make use of the command prompt to use cx_Freeze therefore Python must be available to us as a command. The following video demonstrates how to add Python to your path.


Task

Use the above video to add Python to your system path.


Installing cx_Freeze

cx_Freeze is a utility that will take your Python program and convert it to a stand-alone application (.exe) file that can be run on any Windows computer.

You should download and run the cx_Freeze installer:

If the link is broken try the cx_Freeze homepage:

Creating a script for cx_Freeze

To create a stand-alone application from your program cx_Freeze needs a script to tell it what to do. Because our programs are fairly simple (in the grand scheme of things) all we need to do is make a few changes to the sample program that is provided by cx_Freeze for use with PyQt programs.

The sample script has two lines that we are interested in:

  1. application_title = "simple_PyQt4"
  2. main_python_file = "PyQt4app.py"

You should change the values assigned to the variables application_title and main_python_file so that they are suitable for whatever program you wish to create a stand-alone application for. For example, the field simulation would be:

  1. application_title = "Field Simulation"
  2. main_python_file = "field_simulation.py"

Once you have made the necessary changes save the script and then move it so that it is in the same directory as the Python modules you want to convert to a stand-alone application.

Run the cx_Freeze script

The final step of this process is to execute the cx_Freeze script. The video demonstrates how to do this.


Task

Use the above video to create a stand-alone application.


Final thoughts

In this section you have see how to turn your Python program into a stand-alone application that you can distribute to other people. To do this we modified an example script to get cx_Freeze to perform the necessary operations for us. However, if your application was more complex you made need to modify the script further. The documentation for cx_Freeze should be able to point you in the right direction and there is an excellent mailing list that you can join to get assistance as well.