Install Codon
Codon runs natively on Linux, macOS, and Windows x86-64. Choose the command-line
tool to compile programs, or the Python package to use @codon.jit in an existing
Python application.
- Command-line tool
- Python package
- Linux / macOS
- Windows
Install the Codon CLI with:
/bin/bash -c "$(curl -fsSL https://exaloop.io/install.sh)"
Follow the prompts to add the codon command to your path.
Use a 64-bit PowerShell session on x86-64 Windows. Install the x64 Visual C++ Redistributable if it is not already present, then install Codon with:
& ([scriptblock]::Create((irm https://exaloop.io/install.ps1))) -AddToPath
This downloads the latest Windows SDK and makes codon available in the current
session. The SDK includes the compiler, standard library, runtime DLLs, and Python
package sources.
The installer places the SDK in %USERPROFILE%\.codon, checks that the compiler
can start, and refuses to overwrite an existing destination. Use -InstallDir
to choose a different, unused directory. -AddToPath adds its bin directory to
your user Path for new terminals; omit that switch to leave persistent
settings unchanged. The installer also sets CODON_DIR for the current session.
Use -Version vX.Y.Z to select a release tag, or -Archive <zip> to install a
downloaded SDK. Both direct SDK ZIPs and GitHub artifact ZIPs are accepted.
Keep the installed SDK intact: the compiler and generated programs need its
runtime DLLs. When upgrading, install into a new directory or move the old
installation first.
For codon build, install Visual Studio Build Tools
with the Desktop development with C++ workload, including the MSVC x64 tools
and a Windows SDK. Install LLVM with clang and
lld-link on PATH. Open x64 Native Tools Command Prompt for VS 2022, then
run powershell -NoProfile to use the PowerShell commands in these guides with
the MSVC environment initialized. Check clang --version and lld-link --version
before compiling an executable.
Windows ARM64 SDKs are not currently published. WSL remains an option for using the Linux distribution on Windows; it is not required for the native x86-64 SDK.
- Linux / macOS
- Windows
Use this command to install the codon Python package, which can be used to
compile functions in an existing Python codebase:
python3 -m pip install codon-jit
Install the Windows SDK and C++ build tools described in the command-line tab. Use 64-bit CPython; the Windows CI configuration tests Python 3.13. In PowerShell with the MSVC environment initialized, install the package sources included in the same SDK:
$env:CODON_DIR = Join-Path $HOME ".codon"
$env:PATH = "$env:CODON_DIR\bin;$env:PATH"
py -3.13 -m venv .venv
.\.venv\Scripts\python.exe -m pip install cython setuptools wheel astunparse numpy
.\.venv\Scripts\python.exe -m pip install --no-build-isolation "$env:CODON_DIR\python"
This builds the Python extension against the installed SDK. Keep CODON_DIR
set when using that environment so the package can locate the matching compiler
and runtime libraries.
With this package installed, you can use the @codon.jit decorator.
Learn more.
Run your first program
With the codon command installed, we can compile and run a simple hello-world program:
print('Hello, World!')
If we save this simple program to a file called hello.py, we can compile and run with
the codon run subcommand:
codon run hello.py
This prints the Hello, World! message as expected.
Enable optimizations
By default, codon runs programs without optimizations enabled. You can enable
optimizations with the -release flag. Let's look at a slightly more involved example
to see the effect of this flag:
from time import time
def fib(n):
return n if n < 2 else fib(n - 1) + fib(n - 2)
t0 = time()
ans = fib(40)
t1 = time()
print(f'Computed fib(40) = {ans} in {t1 - t0} seconds.')
This program computes the 40th Fibonacci number using simple recursion. We can run the program with optimizations enabled like this:
codon run -release fib.py
The following measurements illustrate the difference between Python, Codon debug mode and Codon release mode on an M1 MacBook Pro1:
| Command | Time taken (sec.) | Speedup |
|---|---|---|
python3.13 fib.py | 14.26 | 1 |
codon run fib.py | 0.43 | 33 |
codon run -release fib.py | 0.31 | 46 |
These are elapsed times reported by the program around fib(40), not the
total time spent compiling and launching it. The example illustrates native
execution and the release flag, rather than an efficient Fibonacci algorithm;
an iterative or memoized implementation would be more suitable when the goal
is simply to calculate the result. Performance on other workloads and machines
will differ.
The usage guide explains how to separate compilation from execution when measuring an application. From here, functions and generators provide a practical introduction to writing native code, while Python interoperability shows how to use Codon within an existing Python project.