Creating an executable – cxfreeze

Despite its versatility, there are times when you want to run a script on a server (or a computer for that matter) but do not want to install Python. This is especially true for live servers. There are several solutions to create a stand-alone executable you can run; I’ll give a quick start to cx Freeze as the quick start is not at the start of documentation.

As with all good modules you can install with pip; it is named cx-Freeze in pip. It installs the main script into <<PythonInstallDir>>\Scripts called cxfreeze. However it omits the .py extension which is fine for a *nix OS but not for Windows.

Once installed the quickest way to create an executable from your Python script is to change into the Scripts directory and run the following command line (a single command in case of text wrap):

python cxfreeze x:\path\to\script\python_script.py --target-dir x:\path\to\target\folder

This will create the x:\path\to\target\folder with an executable  with the same name as your Python script, the main Python runtime dll and .pyd file (effectively a dll) for each additional Python script your program needs to run. These should be all the files you need to run on a machine without Python installed.

As with everything you need to test this in a suitable environment.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s