How to compile Python code to native executable

First, you need to create a python application, in this case just a “Hello World” file:

$ cat
print "Hello World"

Convert the Python code in C code using Cython:

$ cython --embed

We need to use “–embed” because we don’t want a shared library, but a real main program.

Compile the generated “test.c” file:

$ gcc test.c -o test `pkg-config --libs --cflags python2`

Test it:

$ ./test 
Hello World