How to Create an Executable from Python 3 Code using py2exe
First, install py2exe
Let's build an executable for a sample Python project. We have an addnumbers.py:
that references another module to help add two numbers.
Let's create a Python file (based on this example
) to help build the executable :
from distutils.core import setup
from calc import add
Note that we needed to import the add module from our calc package.
I usually create a batch file (build_exe.bat) to run the Python script:
python build_exe.py py2exe
In PyCharm I now see the files:
Open the directory containing the files and run (double-click) the batch file:
Inside the dist directory is an executable:
Running the executable from the command prompt:
We get our result!
If you'd like, you can download the project here: