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 import py2exe from calc import add setup(console=['addnumbers.py'])
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 pause
In PyCharm I now see the files:
Open the directory containing the files and run (double-click) the batch file:
There are warnings, but the warnings above can be ignored in our case.
Now you should see a dist directory:
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.
Super helpful, thank you!
Leave a comment