📎 Webclip
Tutorial - py2exe.org
py2exe turns Python programs into packages that can run on other Windows computers without Python installed there. The tutorial assumes basic Python knowledge and explains the steps needed after installation, from testing the script to building and checking the output.
Reading notes#
- py2exe runs on a computer that already has Python, because it is itself a Python program and includes parts of Python in the package it builds.
- Before using py2exe, the program should already work; py2exe is not meant to fix a broken script.
- The tutorial’s sample program is a simple
print "Hello World!"script that is tested from the command prompt first. - py2exe extends Distutils with a new command, so the user writes a
setup.pyfile and imports bothsetupandpy2exe. - The sample
setup.pycallssetup(console=['hello.py'])to define a single console application withhello.pyas the entry point. - Running
python setup.py py2execreatesbuildanddistdirectories, withbuildused as working space anddistcontaining the files needed to run the application. - The generated executable is tested from the
distdirectory to confirm that it runs correctly. - The tutorial explains that the Microsoft Visual C runtime DLL may be needed, depending on the Python version and whether the user can redistribute that DLL.
- For Python 2.4 and 2.5, the DLL is MSVCR71.dll; for Python 2.6, 2.7, 3.0, and 3.1, the DLL is MSVCR90.dll.
- If redistribution is allowed, the runtime files can be bundled in a
Microsoft.VC90.CRTsubdirectory throughdata_filesinsetup.py. - If redistribution is not allowed, users must install the appropriate Microsoft Visual C++ Redistributable Package themselves.
- py2exe is not an installer builder; it only assembles the files needed to run the program, so separate installer tools such as NSIS or Inno Setup may be used.
