Things You'll Need:
- Windows computer with a Python environment installed on it
-
Step 1
Create your Python program or import it into the Windows environment.
-
Step 2
Run your code in the Python interpreter and make sure there are no errors in the code:
c:Python\> Python mycode.py -
Step 3
Download the py2exe win32 compiler from the py2exe website (see Resources below).
-
Step 4
Save the downloaded file to disk.
-
Step 5
Open the downloaded file and click through the installation process. This should take a few seconds. The installation will create a py2exe.exe program in your distutils directory distributed with your Python installation that you will use to create the compiled code.
-
Step 1
Open a new text file in Notepad or your favorite editor and save it as mysetupfile.py. This text file will tell the py2exe program which Python programs to convert into an exe.
-
Step 2
Add the following lines in the text file:
from distutils.core import setup
import py2exe
setup(console=['mycode.py'])
where "mycode.py" is the name of your Python program you wish to compile. -
Step 3
Run the mysetupfile.py file through the py2exe program:
c:\Python> Python mysetupfile.py py2exe -
Step 4
Wait until the py2exe compiler finishes producing its output. If all goes well, the compiler may inform you of the DLLs that your Python program is dependent on once it finishes compiling.
-
Step 5
Wait until the compilation is done. Once it is, a directory called "dist" will be created. Enter the directory by type:
c:\Python> cd dist -
Step 6
Look in the directory to see an exe of your project. Test the compile by running the program:
c:\Python> mycode.exe








Comments
csreddy said
on 7/9/2009 The exe works fine, but when i click my exe file , the console shows the result and close immediately.Is there anyway to make console wait for it ?
Thanks,