Converting a Python file into an exe

Say you’ve written a Python program and you want to convert it into an exe and you want the simplest way of going about it.

At this point, there are probably a lot of options out there, but let’s consider two of them — 
1. Py2exe
2. PyInstaller

1) Using Py2exe is very simple and straightforward. Here’s an example -

Imagine you have a Python file that copies a file from one directory to another contingent on its presence in said directory —

Then this file say “” can be converted into an exe using Py2Exe by first generating a file for it.

from distutils.core import setup
import py2exe

Finally, run —

python py2exe

This generates a copy.exe and a python27.dll that is required for its execution.
Now , you could add a option to the file — “ ‘bundle_files’ :1”, but this does not work on x64 based programs.

from distutils.core import setup
import py2exe, sys, os

options = {'py2exe': {'bundle_files': 1, 'compressed': True}},
console= [''],
zipfile = None,

And this reason is why you have option number 2 -

2) PyInstaller

Installing it is as easy as running — pip install pyinstaller

And making the executable just involves running — pyinstaller.exe -onefile

Ta-da! It’s done. Now you can just run your copy.exe from any location as a standalone executable.

Show your support

Clapping shows how much you appreciated Abhiram’s story.