Simple Deployment of a Python Program for Beginners.

Arjun Babu
The Startup
Published in
3 min readAug 3, 2020

I am a Data scientist aspirant and have conducted several data analysis projects but when it comes to delivering to someone with no working knowledge in Computer science we find ourselves in crossroads. I found a simple way to deliver the hard work we put in by building a single executable file(.exe).

My goal here is to help you build a simple Single executable file for a python program.

I will be using a Python version 3.74 on my Mac Book Pro for doing this example. But The process is similar in windows too so it shouldn't be an issue in this case.

STEP-I: Installing PyInstaller.

For achieving this you just have to run the following code in Terminal for a Mac or in cmd For Windows users:

pip install pyinstall

Some time it will require a pip upgrade which could be achieved by using the following command.

python -m pip install --upgrade pip

STEP-II: Building the executable file.

This could be achieved by running the following code.

pyinstaller -–onefile -w --icon="images\myicon.ico" main.py

Here :

  • - -onefile is the command for creating a single executable file.
  • -w is to avoid the console window from running along with the app.
  • - -icon is used to apply an icon of your choice to your application.

There are several other commands available but these are the mainly used basic ones.

The single executable .exe file will be created in the “dist” folder. Which when run will directly open your application.

Here are Some of the problems that I faced during the execution of the above commands:

  1. Hidden import warnings, most of them can be ignored as they are just warnings.
  2. Mac Os:xcrun:error:invalid active developer path, missing xcrun.

To solve this there is an easy fix, we just need to install the Xcode toolkit by using the following command.

xcode-select --install

we might have to re-register it or update it to the latest version sometimes.

We might have to force reset it if this doesn't work by using the following code.

sudo xcode-select --reset

3. Unable to find “/user/nltk_data” when adding binary and data files.

This can be solved by editing the pyinstaller nltk-hook. For this find the NLTK hook file Python folders then change the contents of the file to the following:

import os
import nltk
from PyInstaller.utils.hooks import collect_data_files
# add datas for nltk
datas = collect_data_files('nltk', False)

# loop through the data directories and add them
for p in nltk.data.path:
if os.path.exists(p):
datas.append((p, "nltk_data"))

# nltk.chunk.named_entity should be included
hiddenimports = ["nltk.chunk.named_entity"]

One more thing, you need to rename the file: pyi_rth__nltk.cpython-36.pyc to pyi_rth_nltk.cpython-36.pyc . There should only be one “_” sometimes the file name will have double “_” underscores.

4. In windows, you might face a Path issue where your .py file has to be present in the scripts folder. So simply copy-paste your .py file in scripts folder present in the main python folder which can be found by using the following commands:

For mac devices:

which python

For Windows:

where python

Now This was not the case for everyone so run the code and do this only if you face an issue. Usually, they mention where the file has to be present in the cmd or terminal window so follow the same process but using the path mentioned there.

5. Some modules may not be installed/present in the python folder a simple fix is to go to the python folder path and pip install the missing module. The following general code can be followed in that case.

pip install <Module name>

This should solve most of the issues. I only faced the above issues. In case anyone faces more issues feel free to contact me. Also, I would be thankful if you are willing to share any other problems that you faced while following this article and gladly add that information to this article to further help others.

This is my first article. I am open to suggestions and changes, do let me know if any. This article is for beginners so I have added something that might seem obvious to many, hope it helps someone in need. Thank you for reading my article. happy learning.

--

--