Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't pure Python be fully compiled? [closed]

Tags:

python

Why can't pure Python be fully compiled? Compiled or interpreted is a trait of the implementation, not the language. So shouldn't there be some Python implementation that is fully before-hand compiled to native code? What makes (pure) Python so difficult to compile?

I know there are things like PyPy and Cython but as I understand it those are not pure Python and require things like type annotations, etc.

thanks

Fully compiled meaning compiled before-hand to native code, like C or C++ or Lisp.

like image 795
Aristides Avatar asked Sep 01 '13 10:09

Aristides


People also ask

Is Python pure interpreted or compiled?

For the most part, Python is an interpreted language and not a compiled one, although compilation is a step. Python code, written in . py file is first compiled to what is called bytecode (discussed in detail further) which is stored with a .

Does Python get compiled into C?

Python code can make calls directly into C modules. Those C modules can be either generic C libraries or libraries built specifically to work with Python. Cython generates the second kind of module: C libraries that talk to Python's internals, and that can be bundled with existing Python code.

Can a Python script be compiled?

Python, as a dynamic language, cannot be "compiled" into machine code statically, like C or COBOL can. You'll always need an interpreter to execute the code, which, by definition in the language, is a dynamic operation.

Is Python compiled at runtime?

Python automatically compiles your script to compiled code, so called byte code, before running it. Running a script is not considered an import and no .


1 Answers

False premise. Python can be fully compiled, no type annotations or anything of the sort are necessary.

Furthermore, PyPy does fully compile Python code into machine code. That this isn’t done ahead of time is irrelevant for the aspect of compilability – it’s just an implementation detail of the JIT architecture.

like image 163
Konrad Rudolph Avatar answered Sep 27 '22 21:09

Konrad Rudolph