PyInstaller vs Compiled Python: Which Protects Source?
You’re shipping proprietary Python software and you need to stop customers from reading your source. Both PyInstaller and compiled Python promise the same thing on the surface — one executable you can hand to a customer — but only one of them actually hides your code.
That distinction is the whole buying decision. PyInstaller packages your .py files into an archive that can be unpacked; compiled Python translates your code into native machine code that can’t be trivially decompiled back to readable source. If your goal is convenience, either works. If your goal is source protection, only one of them is doing the job you think it’s doing.
This article is for Python developers shipping commercial desktop apps, CLI tools, or on-prem software who need real code protection — not just a tidy bundle. We’ll compare the two approaches across ease of use, automation, security level, licensing, and how they integrate with the third-party libraries you already depend on.
The Landscape: What Options Exist for Protecting Python Source?
There are four broad families of tools in this space, and they are not equivalent.
PyInstaller — the bundler. It’s the most common way to turn a Python project into a single executable. It wraps your Python bytecode plus its dependencies into one file. It’s convenient and well known, but it is a packaging tool, not a protection tool. The bytecode lives inside the archive, and tools like pyinstxtractor can pull it back out; decompilers can then reconstruct something very close to your original source.
Compiled Python via Cython — the hard way. Cython turns Python-like code into C, which you then compile to native machine code. It genuinely protects your logic, but the workflow is heavy: you write .pyx files in Cython syntax, run a cythonize step, manage C extensions, and configure builds per platform. It’s powerful and it’s a lot of work. We covered that trade-off in depth in Cython Alternatives for Protecting Python Code: Hard Way vs Zero-Config.
Py2Native — the zero-config way. Py2Native also uses Cython under the hood, but it hides the entire Cython layer from you. You keep writing plain Python: no .pyx, no hand-written .pxd, no manual cythonize step, no C extensions to author. One command compiles your modules into native machine code.
Obfuscators and bytecode encryptors. Many tools in this category only rename identifiers or encrypt bytecode that gets decrypted at runtime. The logic is still there — recoverable — and native machine code is a materially stronger barrier than a renamed .pyc.
The rest of this article compares the two options people actually evaluate for a commercial product: PyInstaller and compiling with Py2Native.
Selection Criteria: How to Choose a Source Protection Tool
Before the table, here’s what you should actually be measuring.
- Ease of use. Does the tool force you to write Cython syntax or C extensions? Py2Native doesn’t. You keep writing plain Python, and a build is a single command:
uv run py2native build. - Automation and cross-platform builds. Can you drive Windows, Linux, and macOS builds from CI? Py2Native ships platform plugins for all three and can emit either a PEP 427 wheel containing the compiled
.pyd/.so, or auv-managed deployment directory you can zip and ship. - Security level. Does the tool leave readable source or bytecode behind? PyInstaller leaves recoverable bytecode. Py2Native compiles to native machine code, which makes reverse engineering significantly harder.
- Licensing and compliance. Do you need to enforce licenses at runtime? PyInstaller has no licensing features. Py2Native’s core is MIT open source, and the commercial Pro plugin adds signed JWT license verification. Because third-party libraries stay as Python source, LGPL libraries remain replaceable by the end user — a real compliance benefit.
- Integration with third-party libraries. Py2Native leaves third-party Python libraries unmodified and they work as-is with minimal or no configuration. PyInstaller frequently needs hooks and manual tweaks when you pull in a library with data files, compiled binaries, or dynamic imports.
Side-by-Side Comparison: PyInstaller vs Py2Native
| Criterion | PyInstaller | Py2Native |
|---|---|---|
| Source protection method | Bundles .pyc bytecode into an archive — extractable and decompilable |
Compiles plain Python into native machine code |
| Ease of use | Easy to start; hooks and manual tweaks for complex libraries | Zero config — plain Python plus uv run py2native build main.py *.py --embed dist |
| Cross-platform support | Windows, Linux, macOS | Windows 8+, manylinux2014/musl Linux, macOS via platform plugins |
| Licensing features | None built in | Pro plugin adds JWT/ES256 license verification baked into the binary |
| Third-party library handling | Often requires hooks and configuration | Left unmodified, works as-is with minimal or no configuration |
| Output format | Executable | Executable, or shared library (.pyd/.so/.dylib) plus a wheel, plus uv-managed embed directory |
| License | Free / open source with a bundling exception | MIT core + commercial Pro plugin |
The key differentiator is in the first row. PyInstaller packages your source; Py2Native replaces it with machine code. Everything else — including the build ergonomics — follows from that.
Note also that Py2Native builds run through uv, not pip:
uv run py2native build main.py *.py --embed dist
Requirements are modest: CPython 3.11–3.15 (including the free-threaded 3.14t and 3.15t builds), a platform C compiler and linker (MSVC, GCC, or Clang), and x86-64 or ARM64.
Verdict: Who Should Pick Which?
Choose PyInstaller if:
- You only need convenient packaging — one file, easy distribution.
- Your code is open source or genuinely non-sensitive.
- You don’t need licensing controls or runtime enforcement.
- You’re fine with hooks and manual configuration for tricky dependencies.
Choose Py2Native if:
- You ship proprietary software and the source itself is the asset you’re protecting.
- You want zero-config compilation of plain Python — no Cython syntax, no
.pyxfiles, no.pxdbookkeeping beyond licensing. - You need JWT license verification baked into the binary via the Pro plugin.
- You want to ship an executable, a shared library, or a wheel from the same codebase.
If licensing matters, the Pro workflow is short. Generate an EC P-256 keypair, sign a license payload, and inspect what you signed:
uv run py2native keygen private.pem public.pem
uv run py2native sign --private private.pem payload.json license.dat
uv run py2native show --public public.pem license.dat
Then enforce it inside your own code with the runtime verifier:
license = _runtime_verify_es256_jwt(licenseString, expected_iss="RSJ Software GmbH", expected_aud="TimestampGIT")
The Pro plugin bakes the verification code and the public key into the executable. Only the public key is stored — the private key never leaves your signing machine — which is what makes this safe to distribute. The elliptic-curve verification is handled by compiled code inside the product, with no third-party crypto libraries involved. For the full signing and verification walkthrough, see Verifying Signed JWT Licenses Inside a Compiled Python Executable.
How Py2Native Compiles Plain Python (Without Cython Headaches)
Step 1 — Write plain Python. No Cython syntax, no .pyx files, no manual cythonize step. Your existing modules stay exactly as they are.
Step 2 — Compile. For a native executable:
uv run py2native build main.py *.py --embed dist
For a shared library plus wheel — useful when you’re shipping a package rather than an app:
uv run py2native build main.py mypkg/*.py --library --wheel dist
Add --no-console for a windowed build, and --base <dir> if your source globs are rooted somewhere other than the current directory.
Step 3 — Add license verification (Pro). The licensing flow needs one small declaration file so the compiled module can resolve the runtime verifier:
# license.pxd
from _p2n_bootstrap cimport _runtime_verify_es256_jwt
cdef _runtime_verify_es256_jwt(token, expected_iss=*, expected_aud=*)
Then call it from your own Python code:
license = _runtime_verify_es256_jwt(licenseString, expected_iss="RSJ Software GmbH", expected_aud="TimestampGIT")
And build with the license material in place:
uv run py2native build main.py *.py --embed dist --license license.dat --public public.pem
Step 4 — Distribute. What ships is native machine code, not readable Python. Your third-party dependencies remain unmodified and keep working as-is — that’s the part most code-protection setups get wrong, forcing you into a maze of build configuration before you ever ship anything.
FAQ
Can PyInstaller executables be decompiled back to source?
Yes. PyInstaller bundles Python bytecode into an archive that can be extracted with tools like pyinstxtractor, and that bytecode can then be decompiled to near-original source. It does not compile to native machine code, so it offers limited source protection.
Does Py2Native require me to write Cython or C extensions?
No. Py2Native uses Cython under the hood but hides it completely. You write plain Python — no .pyx or .pxd files, no manual cythonize step, no C extensions. You run uv run py2native build and get a native binary.
How does Py2Native handle third-party libraries? Py2Native leaves third-party Python libraries unmodified and they work as-is with minimal or no configuration. That’s a key advantage over code-protection tools that demand extensive build configuration or per-library hooks.
Can I add license verification to my compiled Python app?
Yes, with the Pro plugin. You generate an EC P-256 keypair with uv run py2native keygen, sign a JWT license with uv run py2native sign, and in your code call _runtime_verify_es256_jwt(licenseString, expected_iss="RSJ Software GmbH", expected_aud="TimestampGIT"). The plugin bakes the public key and verification logic into the executable, so only the public key is stored.
Conclusion
PyInstaller and compiled Python both hand your customer a single executable. Only one of them hands them something they can’t read. If your Python is the product, bundling is the wrong tool — you want compilation, and you want it without rewriting your codebase in Cython syntax.
Py2Native is the zero-config path there: write plain Python, run uv run py2native build, and ship native machine code — with an optional Pro plugin for signed JWT license enforcement. Dependencies stay untouched, builds automate across Windows, Linux, and macOS, and the core is MIT licensed.
Ready to stop shipping your source code? Get started with Py2Native and compile your first module in a single command.
Related posts
- Verifying Signed JWT Licenses Inside a Compiled Python Executable
- How to Ship a Python App Without Exposing Your Source Code
- Automate Python Builds for Windows, Linux, and macOS