Vinay
Vinay

Reputation: 470

python compiler

I have a few queries regarding python

  1. Why is there no python compiler to create native code? I have found py2exe etc but they just pack a python interpreter along with them and hence, it is again the interpreter executing the code.

  2. Is it not possible to create a python compiler like a LISP compiler and hence the code will execute faster(compared to C++)?

Thanks, Vinay

Upvotes: 15

Views: 23855

Answers (6)

sailfish009
sailfish009

Reputation: 2929

LPython: Novel, Fast, Retargetable Python Compiler.

Taichi: Productive & portable high-performance programming in Python.

Codon: A high-performance, zero-overhead, extensible Python compiler using LLVM

Mojo: Mojo combines the usability of Python with the performance of C, unlocking unparalleled programmability of AI hardware and extensibility of AI models.

Upvotes: 1

reclosedev
reclosedev

Reputation: 9502

Nuitka – Python Compiler

What it is

I thought there ought to be possible to use a compiler for Python, a better compiler than what CPython already has with its bytecode. This is what Nuitka is supposed to be.

It is my attempt to translate pure Python not into bytecode, but into machine code (via C++ compiler), while using libpython at run time. And then to do compile time and also run time analysis to speculatively execute things in a faster mode if certain expectations are met.

Upvotes: 17

Liam
Liam

Reputation: 505

Numba is a newer Python compiler based on NumPy & LLVM, which falls back to CPython.

Upvotes: 2

joaquin
joaquin

Reputation: 85613

Question 1:

  • Nuitka (Direct Python code to C++)
  • ShedSkin (Compiles implicitly statically typed Python to C++, stand-alone programs or extension modules)
  • Cython (From a superset of Python to C extensions. Cython comes from Pyrex)

Question 2:
Not sure if I get it correctly but maybe the answer is:

  • psyco (A Just in time compiler (JIT) for Python Code, the predecessor of the PyPy JIT )

Upvotes: 9

Michael0x2a
Michael0x2a

Reputation: 64028

There is, sort of.

  1. See Cython -- I haven't had a chance to fully explore it yet, but as best as I can tell, it directly compiles Python code. You can also use (optional) static typing -- it won't be vanilla Python anymore, but it can lead to a speed boost, if you do it right. Also, see this: Can Cython compile to an EXE?

  2. It might be because I don't have much experience with Lisp, but I'm not entirely sure by what you mean by 'create a Python compiler like a Lisp compiler'.

Upvotes: 2

Raymond Hettinger
Raymond Hettinger

Reputation: 226266

The nearest equivalents for Python are cython and pypy.

Upvotes: 2

Related Questions