Is there anything to translate Python to C code?

Hi, I am looking for a transpiler that converts Python into C, not something like in Cython where it gets transpiled to an extenion?

Cython literally compiles Python code into C, so I’m not sure why that
doesn’t meet your requirements.

You might also check out Nuitka.

From what I heard Cython compiles it into C modules for Python to use, and then you would use something like PyPy.

I think we have to step back and ask “why do you want to compile?”

Is it

  1. For speed?
  2. To create a single-file executable?
  3. Something else?

Depending on which it is, the solution might vary.

I would say all 3

for 3 if it is on a battery powered device, making the CPU do “extra work” will make the battery run out more quickly.

So is there a way to directly compile the entire Python code to C code?

There are a few options, each with their own limitations:

1 Like