When you want to share your software with a non-developer, or you want to run a comprehensive python project without having to bother with the setup, executables are quite useful. And it only takes about 5 minutes to get it done.
⟶
Let’s again start with our favorite barebones setup:
Install pyinstaller globally, or as a dev dependency within your virtualenv:
sudo -H pip install pyinstaller
# or
pipenv install -d pyinstaller
Add the following command to your Makefile
:
installable: dev
pyinstaller -D -F -n demo.exe -c src/demo/main.py --icon=res/icon.ico
Create an icon by converting your favorite image into a .ico file using icoconvert, then place it in a folder called /res
. And finally run:
make installable
The -D
and -F
flag are passed to create one directory, and a one-file bundle respectively.
Your executable should be placed in the dist folder.
Pyenv users may be required to build their python installation with the --enable-shared
flag:
...
INFO: Python library not in binary dependencies. Doing additional searching...
Traceback (most recent call last):
...
Simply run:
# Get numerical portion of python version
PYTHON_VERSION=$(python --version | cut -c8-)
# Uninstall and install python using pyenv
pyenv uninstall $PYTHON_VERSION
env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install $PYTHON_VERSION
https://github.com/pyenv/pyenv/wiki#how-to-build-cpython-with---enable-shared
If you face any other errors, feel free to leave a comment below 👇, and we’ll sort it out.