Convert a Python Script into an executable

This simple guide will show you how you can use pyinstaller and argparse to create a simple console application with python.

Required tools

Lets try this out by creating a simple console app that will list processes or applications that are currently running on your PC.

  1. Create a python script named proclist.py
  • We use psutil.process_iter([‘pid’, ‘name’]) to get a list of all processes running on a machine
  • The argparse ibrary allows the user of our script to specify a limit on the number of processes with print to the console.
  • At this point we can distribute out script as a .py file and any user with python installed on their machine will be able to use our app.

Lets take it a step further

2. Create an executable using pyinstaller

  • Inside the directory where you script is located, run
  • This will create an executable inside distpath directory name proclist.exe
  • At this point we can proceed to run our standalone executable as follows:
  • You should see an output similar to this:

Closing remarks

  • You can go ahead and add the generated executable to the system path so that it can be executed from any location in the command line shell.
  • You might also want to explore the argparse library further to see if you can add more functionality to our simple application. e.g. List 5 applications with the highest cpu usage in the last 5 minutes.

Written by

Former Glorified Electrician(aka Electrical Engineer). Now a Software Developer working on complex Enterprise Software. Lets connect on twitter @NdamuleloNemakh

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store