> For the complete documentation index, see [llms.txt](https://ret2basic.gitbook.io/ctfnote/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ret2basic.gitbook.io/ctfnote/computer-science/python/third-party-library/py2exe.md).

# py2exe

Source code => Windows exe

## What is py2exe

py2exe turns Python programs into packages that can be run on other Windows computers without needing to install Python on those computers. You must run py2exe on a Windows computer. Python is needed on the computer where py2exe itself is run because py2exe is a Python program and it includes parts of Python in the package that is built.

## Installation

```bash
pip3 install py2exe
```

## Template

Write a program and save it as `demo.py`:

```python
print('Hello World')
```

Save the following template as `demo_setup.py`:

```python
import py2exe
from distutils.core import setup

setup(
	options={'py2exe' : {'bundle_files' : 1, 'compressed' : True}},
	console=[{'script' : 'demo.py'}],
	zipfile=None,
)
```

Pack:

```bash
python3 .\demo_setup.py py2exe
```

A `dist` folder will be generated and it contains everything we need to run the executable.
