How to make your life easy with Python executable?

Tej Narayan
3 min readOct 22, 2020

Sometimes I wish life could be easier.

Source: quotesbae.com

Being new to Python, I used to struggle to find ways to automate those hard coded python scripts. As every time I need to open my command prompt and run codes manually one after another.

Than one day, one of my friend suggested to use ‘PyInstaller’, a panacea, which made my day and now its child’s play to convert all those long scripts into an executable file, schedule it as you want and even share it wherever you want to use it. It’s huge relief and save lot of time and effort.

How it works?

To create an executable, first thing we need to do is to install “PyInstaller” i.e.

pip install pyinstaller

2nd we need to go to command prompt (in windows start -> run -> cmd).

Then write the following command where your sync.py (example file) file is kept:

pyinstaller -F -w C:/folder_location/sync.py

After running this command, the folder location of your python script will creates a series of folders and files inside:

Fig: Folders and files created by command

__pycache__, build, dist and two other files.

Inside the dist folder, we will have our executable (in my case its sync.exe) file which can be used as an executable file.

This file can be distributed to anywhere along with all 3 folders mentioned above. Good part is, this can be used without installing python on new computer (only need to copy all these supporting files).

Just to explain what was happened after the above PyInstaller command we ran on command prompt:

‘PyInstaller’ tells the computer to use the module pyinstaller which we have installed earlier.

‘-F’ is an option which tells pyinstaller to only generate one executable and not a series of folders that would also have to be distributed.

‘-w’ is an option which tells the computer to not display a command prompt every time it runs the script.

The path is the path to the python script.

That’s it and we are all done with the help of few steps, we created an executable program.

Isn’t it the easiest way to make an executable with few steps? That’s the beauty of python!!

For more details about PyInstaller, please refer to the below link:

https://pyinstaller.readthedocs.io/en/stable/usage...

Conclusion:

To summarize, this is one of the easiest way to save your precious time and make your life easy while automating your scripts or series of scripts.

Thanks for reading, let me know if you have any other shortcut tip, tricks which can help in automation. please share your feedback at tej_on@outlook.com.

--

--

Tej Narayan

Data Scientist, Passion writing, Data Visualization, Story telling.