Hi guys, in this article, we are going to learn how to convert .py to.exe (native executable) so that you don’t have to install python and its dependencies on every machine you run.
We are going to a popular python library named Pyinstaller to aid our conversion of a python file to a native executable, therefore you might need to install it.
$ pip install PyInstaller
Depending on the operating system you run, PyInstaller will bundle everything up for you to native-run your OS
- For window, it will generate window executable
- For Linux, it will generate a Linux executable
- For Macintosh, it will generate a Macintosh executable
how do we do it ?
For instance, let’s say I’m on a directory containing a Python program of a GUI calculator, There is an article just for that on building a python GUI calculator, to download the source code click Download code.
Your project directory should look like this
. ├── App.py └── calculator .png 0 directories, 2 files
To convert our convert in a distributive form, run the below pyinstaller command on your terminal or cmd, followed by name of your python program as shown below;
$ pyinstaller App.py
............... 5552 INFO: Building EXE from EXE-00.toc completed successfully. 5554 INFO: checking COLLECT 5554 INFO: Building COLLECT because COLLECT-00.toc is non existent 5554 INFO: Building COLLECT COLLECT-00.toc 5919 INFO: Building COLLECT COLLECT-00.toc completed successful
Run your native executable
If you check again on your project folder you will see new folders build and dist, now once you go to the dist folder, you will see many files including executable of your application.
You also check the video demo below;
Based on your interest, you might wanna check out;
- How to track phone number in Python
- How to build a python GUI calculator
- How to make music player in Python
- How to make a digital clock in Python
- How to make a guessing game in Python
Hope you find this post interesting, don’t forget to subscribe to stay updated upcoming python tutorial.
Knowledge is good when shared, therefore feel free to share this article with other developer communities.
In case of any suggestion or comment, drop it on the comment box and I will get back to you ASAP.