15 May 2022
Compile Python on Windows
Looking to create an executable from Python script? Let me show you the full steps to achieve it on Windows. The simple way to add Python to the This box is not enabled by default. You can also manually add the Python installation path to Note You do not strictly have to execute this step, you can also replace This can be Now install Nuitka with the following command. Now run your program from the terminal. Convince yourself that everything is working. Note If it’s a GUI program, make sure it has a In case of a terminal program, add one of many options that Nuitka has to adapt for platform specifics, e.g. program icon, and so on. This will create Your executable should appear right near Steps to create a Windows executable from a Python script using Nuitka
Step 1: Add Python to Windows Path
PATH
do this is to check the box during installation of CPython. You just download python and install or modify Python by checking the box in the installer:PATH
environment variable.python
with just the absolute path, e.g. C:\Users\YourName\AppData\Local\Programs\Python\Python310\python.exe
but that can become inconvenient.Step 2: Open a Windows Prompt
cmd.exe
or Windows Terminal, or from an IDE like Visual Code or PyCharm. And then type python
to verify the correct installation, and exit
to leave the Python prompt again.Step 3: Install the Nuitka Python Compiler package
python -m pip install Nuitka
Step 4: Run your Program
python fancy-program.py
.pyw
suffix. That is going to make Python know it’s one.Step 5: Create the Executable using Nuitka
python -m nuitka --onefile fancy-program.py
python -m nuitka --onefile --windows-disable-console fancy-program.py
fancy-program.exe
.Step 6: Run the Executable
fancy-program.py
and opening the explorer or running fancy-program.exe
from the Terminal should be good.fancy-program.exe