Skip to content

Instantly share code, notes, and snippets.

@vi4hu
Created May 27, 2021 12:30
Show Gist options
  • Save vi4hu/a1aae1a6d209705a14bca2b7c4c7625e to your computer and use it in GitHub Desktop.
Save vi4hu/a1aae1a6d209705a14bca2b7c4c7625e to your computer and use it in GitHub Desktop.
Convert and Compile python in c via cython

steps:

  1. convert .py to .pyx
  2. use cython to convert .pyx to .c
  3. compile .c
  4. Test run

example python file:

script.py

step 1:

you can copy or rename both i am copying

cp script.py script.pyx

step 2:

cython script.pyx --embed

step 3:

gcc -Os -I /usr/include/python3.8 -o script script.c -lpython3.8 -lpthread -lm -lutil -ldl

step 4:

./script

and done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment