Using PyInstaller to Make Distributable Python Tools

Intro

As an attempt to learn more about linux, I installed Fedora on my laptop. I only go to windows when I want to play video games. So, I am usually developing on a linux machine and not on windows. The tools I normally use in linux are not as easily available in a corporate environment with a windows laptop. No vim, terminal, or virtualenvwrapper is easily accessible from windows unless you have Cygwin.

I think I have finally established a set of tools to use in windows for python development: sublime text editor and anaconda. I still have a lot to learn, but I am starting to like how easy it is to manage virtual environments from anaconda. Sublime text comes with its own set of shortcuts, but are sometimes a lot easier.

I like to make python tools at work to make my job easier. Most of my coworkers don’t have python installed, or don’t want to deal with anything programming related. So, I figured out a way to create tools that would help my team with PyInstaller. This enables me to share tools with teammates, and they do not need python installed to run it!

Making a Python Script into an EXE

I will take the BMI program I made in python from the last post and make it into a standalone program to demonstrate PyInstaller.

Step 1. Install PyInstaller

I use this in anaconda prompt on windows, but you can also use this on linux. Just enter the command

pip install pyinstaller

Step 2. Run pyinstaller on the file you want

pyinstaller bmi_calculator.py

This will create a few files. There will be a build folder, dist folder, and .spec file. The program will be in the dist folder. It is important to note that the file is not going to be able to run if you take it out of the dist folder.

Step 3. Test the program

Once PyInstaller is done with creating your program, navigate into the dist folder and click on the exe file with the name of the python file you supplied. Here is a screenshot of the program. I wish there was a way to run the program alone without a cmd window opening, but it will do the job in the meantime.

Conclusion

There you have it! I hope I have shown you how easy making a stand alone file from a python script is. If you already have a python program/script made and want to share with others that do not have python installed, just type the following commands in your terminal:

pip install pyinstaller 
pyinstaller bmi_calculator.py

 

Leave a Reply

Your email address will not be published. Required fields are marked *