Reputation: 470
I have a few queries regarding python
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.
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
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
Reputation: 9502
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
Reputation: 505
Numba is a newer Python compiler based on NumPy & LLVM, which falls back to CPython.
Upvotes: 2
Reputation: 85613
Question 1:
Question 2:
Not sure if I get it correctly but maybe the answer is:
Upvotes: 9
Reputation: 64028
There is, sort of.
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?
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
Reputation: 226266
The nearest equivalents for Python are cython and pypy.
Upvotes: 2