Compiling Your Python
Submitted by lev_lafayette on Fri, 09/30/2022 - 04:08It still generates a little bit of surprise to discover that there are people who use Python on a daily basis that are apparently quite unfamiliar with compiling said code. Or perhaps not; it is, after all, the world's most popular programming language, it has a syntax that's cleaner than many older languages, it has an enormous collection of extensions, and so forth. As a result, there are many people who use Python, but perhaps not so many who have the inquisitiveness and courage, to dive a little deeper. This short article is a deeper dive to understand a little more about the language.
The first common (novice) mistake is that Python is an interpreted language and can't be compiled. It most certainly can and is "compiled", but not in the same way that a compiled language (e.g., C/C++, Fortran, Pascal) is. If this sounds confusing one needs to dig a little into the architecture.
A Python program is compiled before being interpreted, but this step is hidden at the surface level. When Python is executed it generates byte code. This byte code is transformed and interpreted by the Python Virtual Machine which then converts the byte code to binary machine code that the computer processor can output.