From 90c91576aab310f7de159efaed95e79e70d4ce00 Mon Sep 17 00:00:00 2001 From: Shanzia Shabnom Mithun <155734848+shabnomm@users.noreply.github.com> Date: Sun, 16 Aug 2026 11:54:36 +0600 Subject: [PATCH 01/13] Add sample code for Nuitka standalone executable tutorial --- nuitka-standalone-executable/wordcount.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 nuitka-standalone-executable/wordcount.py diff --git a/nuitka-standalone-executable/wordcount.py b/nuitka-standalone-executable/wordcount.py new file mode 100644 index 0000000000..04547108f1 --- /dev/null +++ b/nuitka-standalone-executable/wordcount.py @@ -0,0 +1,12 @@ +from argparse import ArgumentParser +from collections import Counter +from pathlib import Path + +parser = ArgumentParser(description="Show the most common words in a text file.") +parser.add_argument("file", type=Path) +parser.add_argument("-n", "--top", type=int, default=5) +args = parser.parse_args() + +words = args.file.read_text(encoding="utf-8").lower().split() +for word, count in Counter(words).most_common(args.top): + print(f"{word}: {count}") From 4f88fd94e11dc717f8d1f3bedb01336ca7cde529 Mon Sep 17 00:00:00 2001 From: Shanzia Shabnom Mithun <155734848+shabnomm@users.noreply.github.com> Date: Sun, 16 Aug 2026 11:58:32 +0600 Subject: [PATCH 02/13] Add CPU benchmark script to measure performance --- nuitka-standalone-executable/cpu_benchmark.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 nuitka-standalone-executable/cpu_benchmark.py diff --git a/nuitka-standalone-executable/cpu_benchmark.py b/nuitka-standalone-executable/cpu_benchmark.py new file mode 100644 index 0000000000..170d2b844f --- /dev/null +++ b/nuitka-standalone-executable/cpu_benchmark.py @@ -0,0 +1,11 @@ +import math +import time + +start = time.perf_counter() +total = 0.0 +for i in range(20_000_000): + total += math.sqrt(i) +elapsed = time.perf_counter() - start + +print(f"Result: {total}") +print(f"Time: {elapsed:.3f}s") From 1f66d8eb9e3a14c5d2148bf478ce76b59acefa4e Mon Sep 17 00:00:00 2001 From: Shanzia Shabnom Mithun <155734848+shabnomm@users.noreply.github.com> Date: Sun, 16 Aug 2026 11:58:58 +0600 Subject: [PATCH 03/13] Add sample.txt with introductory Python text --- nuitka-standalone-executable/sample.txt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 nuitka-standalone-executable/sample.txt diff --git a/nuitka-standalone-executable/sample.txt b/nuitka-standalone-executable/sample.txt new file mode 100644 index 0000000000..37db2cd82c --- /dev/null +++ b/nuitka-standalone-executable/sample.txt @@ -0,0 +1,5 @@ +Python is a popular programming language. Python is easy to learn, and Python +is also powerful enough for real projects. Many developers choose Python for +web development, data science, and automation. Python code is often easy to +read, which is one reason Python remains popular among beginners and +experienced developers alike. From 98a8af356c3cfdd4e8d8bd4d6597016f41ebd714 Mon Sep 17 00:00:00 2001 From: Shanzia Shabnom Mithun <155734848+shabnomm@users.noreply.github.com> Date: Sun, 16 Aug 2026 12:07:12 +0600 Subject: [PATCH 04/13] Fix print statement formatting in wordcount.py From 84afcd194afdbf0b391942f81653afd9e46d755d Mon Sep 17 00:00:00 2001 From: Shanzia Shabnom Mithun <155734848+shabnomm@users.noreply.github.com> Date: Sun, 16 Aug 2026 12:10:28 +0600 Subject: [PATCH 05/13] Fix print statement formatting in wordcount.py From 6135941e75aad8b3e616059b8cea78b50433a77a Mon Sep 17 00:00:00 2001 From: Shanzia Shabnom Mithun <155734848+shabnomm@users.noreply.github.com> Date: Sun, 16 Aug 2026 12:15:43 +0600 Subject: [PATCH 06/13] Fix print statement formatting in wordcount.py From 41d04cb67300ae91e98cb592881da3fd3d7b6568 Mon Sep 17 00:00:00 2001 From: Shanzia Shabnom Mithun <155734848+shabnomm@users.noreply.github.com> Date: Sun, 16 Aug 2026 12:18:06 +0600 Subject: [PATCH 07/13] Add newline at end of wordcount.py Added a newline at the end of the file for consistency. --- nuitka-standalone-executable/wordcount.py | 1 + 1 file changed, 1 insertion(+) diff --git a/nuitka-standalone-executable/wordcount.py b/nuitka-standalone-executable/wordcount.py index 04547108f1..f351470b0e 100644 --- a/nuitka-standalone-executable/wordcount.py +++ b/nuitka-standalone-executable/wordcount.py @@ -10,3 +10,4 @@ words = args.file.read_text(encoding="utf-8").lower().split() for word, count in Counter(words).most_common(args.top): print(f"{word}: {count}") + From af39784af1de7ff63503ff3f638624523745344a Mon Sep 17 00:00:00 2001 From: Shanzia Shabnom Mithun <155734848+shabnomm@users.noreply.github.com> Date: Sun, 16 Aug 2026 13:21:22 +0600 Subject: [PATCH 08/13] Fix line endings in wordcount.py --- nuitka-standalone-executable/wordcount.py | 1 - 1 file changed, 1 deletion(-) diff --git a/nuitka-standalone-executable/wordcount.py b/nuitka-standalone-executable/wordcount.py index f351470b0e..04547108f1 100644 --- a/nuitka-standalone-executable/wordcount.py +++ b/nuitka-standalone-executable/wordcount.py @@ -10,4 +10,3 @@ words = args.file.read_text(encoding="utf-8").lower().split() for word, count in Counter(words).most_common(args.top): print(f"{word}: {count}") - From ff19d96f438aa2154208881c9086b85e4aaaa4fe Mon Sep 17 00:00:00 2001 From: Shanzia Shabnom Mithun <155734848+shabnomm@users.noreply.github.com> Date: Wed, 19 Aug 2026 13:31:41 +0600 Subject: [PATCH 09/13] Delete nuitka-standalone-executable/wordcount.py --- nuitka-standalone-executable/wordcount.py | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 nuitka-standalone-executable/wordcount.py diff --git a/nuitka-standalone-executable/wordcount.py b/nuitka-standalone-executable/wordcount.py deleted file mode 100644 index 04547108f1..0000000000 --- a/nuitka-standalone-executable/wordcount.py +++ /dev/null @@ -1,12 +0,0 @@ -from argparse import ArgumentParser -from collections import Counter -from pathlib import Path - -parser = ArgumentParser(description="Show the most common words in a text file.") -parser.add_argument("file", type=Path) -parser.add_argument("-n", "--top", type=int, default=5) -args = parser.parse_args() - -words = args.file.read_text(encoding="utf-8").lower().split() -for word, count in Counter(words).most_common(args.top): - print(f"{word}: {count}") From 2a8057a2f12a2cf2bf0d7357ceb5398efc4e4c2e Mon Sep 17 00:00:00 2001 From: Shanzia Shabnom Mithun <155734848+shabnomm@users.noreply.github.com> Date: Wed, 19 Aug 2026 13:32:25 +0600 Subject: [PATCH 10/13] Add wordcount.py to count common words in a file --- nuitka-standalone-executable/wordcount.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 nuitka-standalone-executable/wordcount.py diff --git a/nuitka-standalone-executable/wordcount.py b/nuitka-standalone-executable/wordcount.py new file mode 100644 index 0000000000..6638d678bf --- /dev/null +++ b/nuitka-standalone-executable/wordcount.py @@ -0,0 +1,13 @@ +from argparse import ArgumentParser +from collections import Counter +from pathlib import Path + +parser = ArgumentParser(description="Show the most common words in a text file.") +parser.add_argument("file", type=Path) +parser.add_argument("-n", "--top", type=int, default=5) +args = parser.parse_args() + + +words = args.file.read_text(encoding="utf-8").lower().split() +for word, count in Counter(words).most_common(args.top): + print(f"{word}: {count}") From 0d8f5b2f6e4deb7b296eab77bb1f1ea7c9acc172 Mon Sep 17 00:00:00 2001 From: Shanzia Shabnom Mithun <155734848+shabnomm@users.noreply.github.com> Date: Wed, 19 Aug 2026 13:41:12 +0600 Subject: [PATCH 11/13] Update wordcount.py From a6125f9fc75d84dba814f5dce8061543f6fb26b9 Mon Sep 17 00:00:00 2001 From: Shanzia Shabnom Mithun Date: Wed, 19 Aug 2026 13:59:43 +0600 Subject: [PATCH 12/13] Fix code formatting with ruff --- nuitka-standalone-executable/wordcount.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nuitka-standalone-executable/wordcount.py b/nuitka-standalone-executable/wordcount.py index 6638d678bf..f16a4fef61 100644 --- a/nuitka-standalone-executable/wordcount.py +++ b/nuitka-standalone-executable/wordcount.py @@ -2,7 +2,9 @@ from collections import Counter from pathlib import Path -parser = ArgumentParser(description="Show the most common words in a text file.") +parser = ArgumentParser( + description="Show the most common words in a text file." +) parser.add_argument("file", type=Path) parser.add_argument("-n", "--top", type=int, default=5) args = parser.parse_args() From 46f9d54150d6c814ed2baa26d37259ecc291fe7c Mon Sep 17 00:00:00 2001 From: Shanzia Shabnom Mithun <155734848+shabnomm@users.noreply.github.com> Date: Wed, 19 Aug 2026 14:04:39 +0600 Subject: [PATCH 13/13] Create README.md for Nuitka standalone executable Add README for Nuitka standalone executable usage and examples. --- nuitka-standalone-executable/README.md | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 nuitka-standalone-executable/README.md diff --git a/nuitka-standalone-executable/README.md b/nuitka-standalone-executable/README.md new file mode 100644 index 0000000000..cb4d916009 --- /dev/null +++ b/nuitka-standalone-executable/README.md @@ -0,0 +1,29 @@ +# Nuitka: Compile Your Python Code Into a Standalone Executable + +Sample code for the Real Python tutorial on compiling Python applications with Nuitka. + +## Files + +- `wordcount.py`: A small command-line tool that counts the most common words in a text file +- `sample.txt`: Sample text used to test `wordcount.py` +- `cpu_benchmark.py`: A CPU-bound benchmark script used to compare runtime performance across regular Python, `--mode=standalone`, and `--mode=onefile` builds + +## Usage + +Install Nuitka: + +```console +$ python -m pip install nuitka +``` + +Compile `wordcount.py`: + +```console +$ python -m nuitka --mode=standalone wordcount.py +``` + +Run the compiled executable against `sample.txt`: + +```console +$ ./wordcount.dist/wordcount sample.txt -n 5 +```