Python: Make Standalone EXE for any Python Script

Hi,

First of all we need to install py2exe. You will find setup files which will install this without any issues.

Find then here:

http://sourceforge.net/projects/py2exe/files/py2exe/0.6.9/

Make sure to use proper version. If you download a 32 bit version and it says "Python Installation not find in registry, or something like that", then install a 64 bit, as you may have 64 bit python. Act accordingly.

Now we have to check if it is working. Open python console and run like this:



If you see no error, you are good to go.

Now create a folder and make a file inside this folder named as printscr.py. Write any python script there. We will be using below script that prints output 9 times.

for i in range(1, 10):
    print('What have I done !!!!')
raw_input()


Now create another new file with name setup.py. Write below lines in this file:

from distutils.core import setup
import py2exe

setup(console=['printscr.py'])

Now open command prompt, navigate to your folder and run below command:

python setup.py py2exe

You will see some output flows, but you don't need to bother with details. Now, if everything went well, you will see few folders that have just appeared magically. 

Go to "dist" folder, here you will find your exe names as  printscr.exe. This is it. Run this file and check that everything is working as intended.


Comments

  1. If you don't want console to display, you'll have to change "console=" to "window="

    ReplyDelete

Post a Comment