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

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

  • Installing application-compatible Python version
  • Installing related Python packages
  • Setting up environment variables on user machines
  • Updating the application with newer versions whenever needed

All of this can be a bit hectic. I got first-hand experience working on an analytics project for our medical KPO client. Their existing analytics were 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 a few business users to test the beta version of it.

While planning the deployment process, we realized that as a prerequisite for deploying the application, we would have to install many related packages for each programming language.
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 routine of deploying a set of code on a user’s machine.

There are multiple ways to create executables for Python code!

Ways to create executables for Python Code

Using Python’s py2exe module

  1. You can simply install py2exe by running pip on the 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 the following content in it:
    From distutils. core import setup
    import py2exe
    options = {‘includes’:[‘math’]} #Here you must add list of identified modules
    setup(windows=[‘my_script.py’]) #Here mention your driver python script name
    Here, instead of Windows, you can also use the console option to track errors or warnings while running exe.
  5. There is another case; if you want to add data files such as gifs, images, or any other files while running application, then you must add them as:
    Mydata_files = [(‘images’, [‘c:/path/to/image/image.png‘])] #Here mention file name
    setup(
    windows=[‘my_script.py’],
    data_files = Mydata_files)
  6. Save and Close the setup.py file.
  7. Now, to generate .exe file in the required directory, use the following command in the command prompt:
    python setup.py py2exe
  8. Two folders will be formed if the exe is created successfully. These are named dist, and these will be created within the same directory. You will also find the exe in the dist folder.
  9. Now, you can deploy the application by placing these folders on the client machine without installing any programming language packages!

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 –one file your_main_file.py
  3. Follow step 8 of the 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:

Recommendation

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

Emergys Blog

Recent Articles

  • Service Desk Automation

    Top Candidates for Service Desk Automation

    Top Candidates for Service Desk Automation

    Automation is not new to anyone. It is the foundation [...]

    Automation is not new to anyone. It is the foundation for any enterprise digitization. However, companies [...]

  • Maximizing Customer Engagement with Salesforce

    Maximizing Customer Engagement with Salesforce

    Maximizing Customer Engagement with Salesforce

    Forget about closing deals – in today's business world, customer [...]

    Forget about closing deals – in today's business world, customer engagement is all about building bridges, [...]

  • Bridging the Gap Between Humans and Machines with Generative AI

    Bridging the Gap Between Humans and Machines with Generative AI

    Bridging the Gap Between Humans and Machines with Generative AI

    Nowadays, customers expect quick and thorough help whenever they reach [...]

    Nowadays, customers expect quick and thorough help whenever they reach out, whether it’s to order something, [...]