Skip to content

Instantly share code, notes, and snippets.

@danzz006
Forked from vi4hu/pytoc.md
Created November 14, 2022 06:57
Show Gist options
  • Save danzz006/3455f4abe6e5ecaf301a0454e00874e3 to your computer and use it in GitHub Desktop.
Save danzz006/3455f4abe6e5ecaf301a0454e00874e3 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