Why we need Python interpreter?

When we write Python code, we get a text file with the .py extension containing the Python code. To run the code, you need a Python interpreter to execute the .py file.
Because the entire Python language is open source from the specification to the interpreter. So in theory, as long as the level is high enough, anyone can write a Python interpreter to execute Python code (of course it is difficult). In fact, there are multiple Python interpreters.

CPython

When we downloaded and installed Python 3.x from the official Python website, we directly got an official version of the interpreter: CPython. This interpreter was developed in C, so it is called CPython. Running python from the command line starts the CPython interpreter.
CPython is the most widely used Python interpreter. All the code of the tutorial is also executed under CPython.

IPython

IPython is an interactive interpreter based on CPython, that is, IPython is only enhanced in an interactive way, but the function of executing Python code is exactly the same as CPython.

PyPy

PyPy is another Python interpreter whose goal is execution speed. PyPy uses JIT technology to dynamically compile Python code, so it can significantly improve the execution speed of Python code.
Most Python code can be run under PyPy, but PyPy and CPython are different, which results in the same Python code may have different results when executed under two interpreters. If your code is to be executed under PyPy, you need to understand the differences between PyPy and CPython.

Jython

Jython is a Python interpreter running on the Java platform, which can directly compile Python code into Java bytecode for execution.

IronPython

IronPython is similar to Jython, except that IronPython is a Python interpreter running on the Microsoft .Net platform. It can directly compile Python code into .Net bytecode.

Summary

There are many interpreters for Python, but the most widely used is CPython. If you want to interact with the Java or .Net platform, the best way is not to use Jython or IronPython, but to interact through the network to ensure the independence of each program.
All the code in this tutorial is only guaranteed to run under CPython 3.x. Be sure to install CPython (installer downloaded from the official Python website).

Last modified: January 9, 2020

Author

Comments

Leave a Reply