15

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

1

6 Answers 6

17

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you.. This is the first time i'm hearing about this after searching for quite some time, and it seems very interesting. This was something I was looking for.. :) I have not checked how it works.
9

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 )

Comments

2

The nearest equivalents for Python are cython and pypy.

Comments

2

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'.

2 Comments

I read somewhere there exists a LISP compiler and performance of LISP program is comparable to C++. Am I wrong? Can LISP compiler create native executable?
Ah, I misunderstood your original question. Yes, some Lisp compilers can create native executables. Cython (which I linked above) does nearly the same thing.
2

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

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.