Why I lied when I said that Python does not have a compiler

Опубликовано: 09 Ноябрь 2024
на канале: Python for Everyone
139
14

In this video you learn what a compiler does and the answer to this important question: Does Python have a compiler?

Source code written by us developers, needs to be converted to executable programs. For this, there are two common techniques. A compiler can process the source code and generate an executable program for a specific architecture like arm, x86 or an Apple M-processor. When programs are compiled for specific architectures, static types can be used to optimize performance. For example, the compiler can decide to use hardware acceleration for specific operations.

There is also a downside of course and that is that programs have to be compiled for each platform and architecture. The resulting binaries cannot be exchanged between platforms. An alternative is to create some kind of virtual machine for each platform. This way the same source code can be used to feed each virtual machine, regardless of the platform it is running on. The Python interpreter functions as a virtual machine and does even more.

"pyc" means python compiled. Yep. Python does have a compiler to create byte-code. The byte-code is compiled for the interpreter that was used to execute the script. So what happens if this exact project is run on another Python configuration?