Page 1 of 1

py2exe:making exe file from python script

#1 atik97  Icon User is offline

  • ???
  • member icon

Reputation: 144
  • View blog
  • Posts: 715
  • Joined: 16-September 08

Posted 18 December 2008 - 05:44 PM

To run python programs on any windows platform where python is not installed, it is necessary to make exe file. This can be done using py2exe. This tutorial will show how to turn python scripts into exe file.

Say we have a python program name sample.py. We want to make exe file for this program. At first install py2exe. Make sure your python program is running from command prompt. For that, run the command prompt and type the following code-

C:\Documents and Settings\atik>python sample.py



If it runs successfully, that's nice. Otherwise you need to set environment variables. Follow the steps bellow:
Control Panel-> System -> Advanced -> Environmental Variables -> System Variables -> New -> Variable Name - Python25 & Variable value -%Python25%;C:\Python25.

Two steps are required now- 1. Create setup script 2.Run setup script

Create setup script
Open your editor(IDLE) and type the code below-

from distutils.core import setup
import py2exe
setup(console=[‘sample.py’])



Save the file as setup.py .

Run setup script
Run the command prompt and type the code

C:\Documents and Settings\atik>python setup.py py2exe



You will see lots of output like this—
C:\Documents and Settings\atik>python setup.py py2exe
running py2exe
*** searching for required modules ***
*** parsing results ***
creating python loader for extension 'zlib'
creating python loader for extension 'unicodedata'
creating python loader for extension 'bz2'
*** finding dlls needed ***
*** create binaries ***
*** byte compile python files ***
byte-compiling C:\ Documents and Settings\atik \build\bdist.win32\winexe\temp\bz2.py to bz2.pyc
byte-compiling C:\ Documents and Settings\atik \build\bdist.win32\winexe\temp\unicodedata.py to unicodedata.pyc
byte-compiling C:\ Documents and Settings\atik \build\bdist.win32\winexe\temp\zlib.py to zlib.pyc
skipping byte-compilation of c:\Python25\lib\StringIO.py to StringIO.pyc
skipping byte-compilation of c:\Python24\lib\warnings.py to warnings.pyc
*** copy extensions ***
*** copy dlls ***
copying c:\Python25\lib\site-packages\py2exe\run.exe -> C:\ Documents and Settings\atik \dist\hello.exe

Two directories will be created when you run your setup script... build and dist. The build directory is used as working space while your application is being packaged. It is safe to delete the build directory after your setup script has finished running. The files in the dist directory are the ones needed to run your application.

Is This A Good Question/Topic? 3
  • +

Replies To: py2exe:making exe file from python script

#2 higharc91  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 07-June 13

Posted 07 June 2013 - 07:51 PM

Hi there new here, quick question. Can you use py2exe with any type of gui modules? If so is there any drawbacks to executing on other pcs without python, or the modules?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1