Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python compiler

Tags:

python

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

like image 205
Vinay Avatar asked Jan 06 '12 05:01

Vinay


People also ask

Is there a Python compiler?

Python is an interpreted programming language and has different execution environments. It has a wide range of compilers to execute the python programs eg. PyCharm, PyDev, Jupyter Notebook, Visual Studio Code, and many more.

What is Python compiler or interpreter?

Python is an interpreted language, which means the source code of a Python program is converted into bytecode that is then executed by the Python virtual machine. Python is different from major compiled languages, such as C and C + +, as Python code is not required to be built and linked like code for these languages.

Can I run Python code online?

To run Python code online, write your Python code in the editor and press the Run button to execute it. You will see the result in your browser. This online IDE works with Python 3.


2 Answers

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.

like image 105
reclosedev Avatar answered Oct 17 '22 13:10

reclosedev


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 )
like image 9
joaquin Avatar answered Oct 17 '22 13:10

joaquin