Python is a well known language for rapid development. Also, it is one of the most versatile languages because of rich libraries available in it. These days most of the organizations use Python for implementing Data science projects as it has many connectors to data science related libraries. At Ellicium, we are in love with Python and everything it has to offer. Ellicians have also written some articles expressing their love for it.

Yet, developing Python application is one thing and deploying them on user machines is another. Deploying Python application can become a tedious activity as it involves below-mentioned things:

Installing application compatible Python version

Installing related Python packages

Setting up environment variables on user machines

Updating the application with newer version whenever needed

All of this can be bit hectic. I got the first-hand experience of it while working on an analytics project for our medical KPO client. Their existing analytics was based on combinations of programming languages including Python. Our task was to empower it further. We had developed Python based applications for the same and we wanted few business users to test the beta version of it. While planning the deployment process, we realized that as a perquisite for deploying the application, we will have to install a lot of related packages for each of the programming languages.

Quite evidently, it turned into a nightmare!

After uncounted rounds of coffee, we found a better way to do it. This profound way is called ‘Creating Executables’. It triumphs over the hectic way of deploying a set of code on user’s machine.

There are multiple ways to create executables for Python code!

Ways to create executables for Python code

A) Using Python’s py2exe module

1) You can simply install py2exe by running pip on command prompt

pip install py2exe

2) Make sure the script that you have developed is syntactically and functionally correct.

3) Fetch a list of packages you have used in your Python script, which can be as follows:

import math
import Pyqt4

4) Create and open setup.py script to create exe from it and write following content in it:

7) Now, to generate .exe file in the required directory use following command in command prompt:

python setup.py py2exe

8) If exe is created successfully then as aftereffect two folders will be formed. These are named as dist and these will be created within the same directory. You will also find exe in dist folder.

9) Now you are ready to deploy the application by simply placing these folders on the client machine without installing any programming language packages!

B) Using Python’s Pyinstaller module :

1) You can simply install pyinstaller using pip on cmd:

pip install pyinstaller

2) Use the command prompt to traverse to the path where your scripts are placed and execute the following command:

python pyinstaller.exe -–windowed –onefile your_main_file.py

3) Follow step 8 of py2exe method

You might be wondering which method to choose out of these two. To make it easy below is the comparison between these two methods:

Diagram: Comparison between py2exe and pyinstaller

Recommendation:

I would recommend using Pyinstaller as it is easy to create exe using pyinstaller than py2exe. Pyinstaller needs only single command to create exe whereas py2exe requires setup.py script to be created first and then command to create exe.

In case you want to know more about this, you can get in touch with me here: sujata.khedkar@ellicium.com