Turning the python script into an executable
There are a few ways to create a windows executable from python code. I’ll be discussing two of them - pyinstaller and cx_Freeze. You can use either of these. This page will give a short summary of how to use them. Refer to their documentation for for more detailed help if you need it.
option 1: pyinstaller
install pyinstaller with pip:
pip install pyinstaller
The simplest way of creating an executable with pyinstaller looks like this:
pyinstaller yourprogram.py
This creates a bunch of files and two directories: build
and dist
. Your executable will land in dist
.
..but if you try this, you’ll notice that it does not bundle any extra files that your program requires (such as your animations).
To do this, you’ll need to copy the files to the destination directory. You can use the --add-data
flag to achieve this or just copy the files yourself. The -y
flag overwrites the existing directory without prompting.
pyinstaller -y --add-data '*.gif;.' yourprogram.py
--add-data '*.gif;.'
means copy all .gif
files to the root of the executable folder.
or (for all animations)
cp youranimation.gif dist\yourprogram\
option 2: cx_Freeze
install cx_Freeze with pip:
pip install cx_Freeze
The syntax for using cx_Freeze, outputting to the same directory as the pyinstaller example is:
cxfreeze -c yourprogram.py --target-dir dist\yourprogram
you’ll also have to copy the animations to the executable folder, like with pyinstaller
Things to be aware of
Pyinstaller and cx_Freeze both have issues with antivirus false positives. I believe cx_Freeze is a little better in that regard, but I’ve heard that it happens with it too.