You will need to ensure that you have a script installed in order to compile your Python script in to a exe file.
The easiest way to do this is on a Windows machine with Python installed, however it can be done under Linux using wine.
I will cover how to install wine on Linux and set up an environment (prefix) for that and then from there the options are broadly similar between Linux/wine and Windows.
Install wine
pacman -S wine
apt install wine
dnf install wine
Create a wine prefix
WINEPREFIX="$HOME/.wine-python" WINEARCH=win64 wineboot
cd $WINEPREFIX
Download the Windows Python installer from the Python site.
wget https://www.python.org/ftp/python/3.12.0/python-3.12.0-amd64.exe
- correct at time of writing
Install Python using wine and the Windows installer
WINEPREFIX="$HOME/.wine-python" wine python-3.12.0-amd64.exe
Install may fail with a message explaining that Windows 8.1 or Windws Server 2012 or newer are required in order to install Python (see example example screenshot below). If this happens, then you will need to configure use wine to use the correct version. You can do this by running
WINEPREFIX="$HOME/.wine-python" wine winecfg -v win10
WINEPREFIX="$HOME/.wine-python" wine python --version
For r this we will need to run pip via wine and tell it to install pyinstaller:
WINEPREFIX="$HOME/.wine-python" wine pop install pyinstaller
Installation of pyinstaller should now be complete. Next we need to create the Windows exe file:
WINEPREFIX="$HOME/.wine-python" wine pyinstaller your-python-script.py
This will create a file called "your-python-script.exe" in the "dist" directory by default along with dependencies. This will create an application which is relatively quick to launch. My preference is to create a single file exe where everything is bundled in to it. We do this by running the following command:
WINEPREFIX="$HOME/.wine-python" wine pyinstaller --onefile your-python-script.py
This exe will take slightly longer to open as it has to decompress the bundled dependencies. You may also notice that there is a console window along side the GUI. This is probably undesirable, unless required for some debugging operations. You can get rid of the window by running with the --noconsole
switch like this:
WINEPREFIX="$HOME/.wine-python" wine pyinstaller --onefile --noconsole your-python-script.py
The resulting exe file will always been named whatever your .py file is called. You can however change this by using the --name
switch like this:
WINEPREFIX="$HOME/.wine-python" wine pyinstaller --onefile --noconsole --name my-application your-python-script.py
the .exe will be automatically appended by pyinstaller