Python Virtual Machine

  Installation of Python - This can be done from python.org

To check version - Python --version - Windows / Python3 --version - MacOs

With installation of python, it provides an interactive shell to start creating a python program. (Python IDL). Provides facility to run single line command. 

Code Editor 

To create full-fledged program, we will need a text/code editor - Example Vscode. In vscode we can install plugins to run multiple programming languages including C, C++,Java,Python,Javascript and many more. 

Run Python 

python programName.py | python3 programName.py ( MacOs)

Python Virtual Machine

 In C/C++ software/application is created as follows:


Computer's hardware consists of electronic, mechanical and magnetic devices which are capable of storing signals and charge. By default, it is designed to store information and process them using various components such as gates, diodes, transistors forming Integrated Circuit. 

It's difficult for the individuals to use such hardware directly, so there should be some mechanism to operate hardware. This is provided by Operating System which operates as a manager insuring coordination and efficient use of hardware. It acts as a central system and coordinate entire hardware use. We can say without operating system hardware is merely a black box. 

There are various operating systems specific to hardware such as Windows, MacOs , Unix, Linux etc. 
These operating system interpret instruction based on the architecture it is based; earlier there used to 16 bit/32 bit machines , nowadays we have 64 bit machines which can process instruction in the form of 64 bit blocks providing better memory utilization and increased performance. 

To note - instruction generated in one operating system have different interpretation to those generated in different set of operating system. Operating systems are designed to understand machine codes which resembles to binary set of instructions. Now to perform any operation, one has to generate binary sequence so that Operating system can efficiently use to operate hardware and perform some computations. 

How this can be resolved? Any solution . Fortunately programmers have worked tirelessly to make things easy for us. Yes! without having trouble of understanding machine sequence, we can use software such as assemblers, compilers and interpreters to write plain text which can be further translated to operating system instruction and subsequently operating system can work with hardware. 

Example in C - we have built tools (preprocessor, compiler and linker) which can generate machine code from C source code. Learning C language can provide efficient way to write instructions for operating system in any operating system. But as the machine codes are varied largely based on the operating system architecture, code written in one operating system cannot run directly in another. There is option to build the machine files using built tools. Hence, we say C language is platform dependent (By platform we mean Operating System and Hardware). But Python is not platform dependent, and a python code written can run in all the OS. 


How is this achieved? 

Solution is Byte code ...

and Python Virtual Machine (Specific to Operating System). 

Now Platform means - Hardware, OS and PVM.  














Python uses similar concept to Java where entire source code is compiled to Byte code (.pyc). This bytecode is designed to run with special software called as Python Virtual Machine. 

PVM is downloaded along with python installation specific for operating system. It is designed in such a way that it can execute byte code for particular OS. So PVM for windows would be different from those of MacOS and so on. 

PVM is internally designed to read byte code one by one and provide the converted machine code to OS. So PVM doesn't read entire bytecode file but fetch instruction one by one and provide machine code sequence to OS. Unlike interpreter, PVM doesn't wait for a particular instruction to be completed, it fetches next instruction and keep it ready in some memory which is immediately available to OS. This is done via presence of software called as JIT - Just in Time compiler ( Its different from compiler in a sense it doesn't generate entire machine code from byte code but takes one instruction from bytecode file and provide same to OS.) 

Apart from JIT compiler, PVM has memory manager which frees files not required, such as .pyc file which gets deleted once python code is execute. If we want to save pyc file, it can be done with below command.

Generate Pyc file using - python -m file.py compile











Comments