Python to Exe – PyInstaller – in 2 Mins

How to convert Python program to Exe file?

Though there are different options to convert Python to Exe file, I prefer PyInstaller. It converts Python program to executable and also includes the additional libraries included in your program.

So, in the target computer there is no need to install Python or required libraries. More over PyInstaller is available for Windows, Max & Linux. But it does not create a cross platform enabled executable file as mentioned in this official page.

Note: It is assumed that you have the latest Python installed. This methods is tested & works fine in Windows 10 PC.

Pyinstaller: Python to Exe steps

Package we are going to use to make Python exe is called PyInstaller. Follow these steps.

  1. Open cmd & type: pip install pyinstaller
  2. Open folder that has the python program (.py file)
  3. Shift + Right click inside the folder.
  4. Choose: Open Powershell Window here
  5. Type ths command in powershell window:
    • pyinstaller –onefile ‘myPythonProgramName.py’
    • Press ‘Enter’ key

Wait for few seconds. This process will create 3 folder. We need only the dist folder. This folder will have myPythonProgram.exe which can be distributed to your client & hence the name dist.

Issues while Exe creation: Follow this link to resolve any issues you encoutner during a executable file creation. Click here

Cross Platform – Windows/Mac/Linux

PyInstaller is available for multiple OS platforms. But the resulting exe is not cross platform.

This means: If you want to run a Python exe in a Windows PC, it has to be compiled in Windows PC. If target machine is Linux, then create exe in a Linux machine.

Using these steps above, the whole process takes 2 to 5 mins. Python has been used in a variety of environments due to the availablility of numerous libraries. So, this kind of compilers will enable more users to like this wonderfull programming language.