0% found this document useful (0 votes)
12 views

How is Python Source Code Converted Into Executable Code

Uploaded by

Suriya Sur
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

How is Python Source Code Converted Into Executable Code

Uploaded by

Suriya Sur
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

How is Python Source Code Converted into Executable Code

The Python source code goes through the following to generate an executable code

• Step 1: The Python compiler reads a Python source code or instruction in the
code editor. In this first stage, the execution of the code starts.

• Step 2: After writing Python code it is then saved as a .py file in our system. In
this, there are instructions written by a Python script for the system.

• Step 3: In this the compilation stage comes in which source code is converted
into a byte code. Python compiler also checks the syntax error in this step and
generates a .pyc file.

• Step 4: Byte code that is .pyc file is then sent to the Python Virtual
Machine(PVM) which is the Python interpreter. PVM converts the Python byte
code into machine-executable code and in this interpreter reads and executes
the given file line by line. If an error occurs during this interpretation then the
conversion is halted with an error message.

• Step 5: Within the PVM the bytecode is converted into machine code that is the
binary language consisting of 0’s and 1’s. This binary language is only
understandable by the CPU of the system as it is highly optimized for the
machine code.

• Step 6: In the last step, the final execution occurs where the CPU executes the
machine code and the final desired output will come as according to your
program.

How Python Internally Works?

• Code Editor: Code Editor is the first stage of programs where we write our
source code. This is human-readable code written according to Python’s syntax
rules. It is where the execution of the program starts first.

• Source code: The code written by a programmer in the code editor is then saved
as a .py file in a system. This file of Python is written in human-readable language
that contains the instructions for the computer.

• Compilation Stage: The compilation stage of Python is different from any other
programming language. Rather than compiling a source code directly into
machine code. python compiles a source code into a byte code. In the
compilation stage python compiler also checks for syntax errors. after checking
all the syntax errors, if no such error is found then it generates a .pyc file that
contains bytecode.
• Python Virtual Machine(PVM): The bytecode then goes into the main part of the
conversion is the Python Virtual Machine(PVM). The PVM is the main runtime
engine of Python. It is an interpreter that reads and executes the bytecode file,
line by line. Here In the Python Virtual Machine translate the byte code into
machine code which is the binary language consisting of 0s and 1s. The machine
code is highly optimized for the machine it is running on. This binary language is
only understandable by the CPU of a system.

• Running Program: At last, the CPU executes the given machine code and the
main outcome of the program comes as performing task and computation you
scripted at the beginning of the stage in your code editor.

You might also like