In this lesson, we will cover some of the Python compilers and interpreters available for Python programming language. We will try to establish the use-cases in each of the interpreters and identify if any of them are available online where we can try them without any installations. Also we will see what advantages they offer apart from specific technical advantages.
Table Of Contents
- 1. Introduction
- 2. Python Compilers and Interpreters
All of the tools are not available online to try. Some of the tools needs to be installed on our system, some can be downloaded & used directly from a Windows directory without any installation and remaining can be tried online in the web browser directly. The tools we will discuss here are usually part of a Python programmer lifestyle every day (not all of them but at least one is). The list of Python compilers and interpreters which we will discuss in this lesson is as follows:
- Stackless Python
- Shed Skin
This is the list with the 10 most popular Python compilers and interpreters. We picked these Python Compilers and Interpreters as they are very interesting and each of us should know. It is possible that not each of the Python programs can be executed in all of them as they bring something specific to the table too, otherwise, there is no reason why all of them exists for exactly the same task. Please note that all of these tools are free of cost which can be used in any commercial or development in software systems. Let’s start by looking at each one of them in some detail.
Before we dive into the types of Python Compilers and Interpreters, be ready for some surprises and good learning which you will get from these points. Many of these Python Compilers and Interpreters are not well known because they are used in some very specific use-cases only but nonetheless, they are still important and knowledge of their existence will only help you.
Let’s start with one of the Python compilers and interpreters we mentioned above and continue with the others as we go along in this lesson. We will pick CPython as our opener.
We started with CPython for a reason. This is because this is the one which is most widely used implementation of Python. This interpreter is the default interpreter which we use when we install Python on our machines and this interpreter is written in C-programming language. It is termed as CPython as this interpreter contains a lot of interfaces as foreign functions with languages like C itself. CPython is the recommended implementation for Python when all you need is compatibility and compliance with industry standards in Python than raw performance.
As this is the most widely used version of Python, we can almost say that we all start by learning CPython and then probably move to other interpreted versions of CPython itself. We can quote from the Python official documentation, that:
CPython incorporates modules, exceptions, dynamic typing, very high-level dynamic data types, and classesPython official documentation
With CPython, it is possible to:
- Calls C and C++ code back and forth, directly from Python code, natively
- Combine source code level debugging to dive into your Python code to find memory leaks, efficiency bottlenecks etc.
CPython can be termed as a superset of the Python programming language that additionally enables us to call C functions, declaring C data types in variables. Finally. Cython is freely available under the open source Apache License.
As it sounds, Jython is an implementation of the Python language to be able to run on the Java Virtual Machine. This means that we can make seamless use of third-party Java libraries and other Java-based applications. Even though almost all of the Python code be run on the JVM with Jython, there are some differences in some of the modules.
One of the major gaps between the normal Python code and one run on JVM is that Jython does not work with C extensions. This is however not a big problem because there are a lot fewer chances that you are actually using any of the C extensions in your Python program and in that case, the program will work just fine. Here are some few quick points about Jython:
- Jython was first released in January 2001 and last stable version was released on July 2017
- Jython simply takes a Python code and compiles it to corresponding Java bytecode. This is why we can Jython on any system which runs a JVM
- We can extend Java classes with Jython as well
To mention explicitly here, Jython works with JVM but CPython (which we mentioned in the last section) will not work with the JVM. Finally, Jython code will work on CPython though, unless it doesn’t have any Java libraries used in it.
Now that we have studied about normal Python distribution interpreter and the Java version of Python, Jython, it is time that we also don’t leave the .NET framework behind. There is a Python implementation for .NET framework as well, which is called the IronPython. Here are some few quick points about IronPython:
- IronPython was first released in September 2006 and last stable version was released on February 2018
- IronPython is written in the C# programming language
- IronPython also supports a REPL environment, or simply stated, an interactive console which supports dynamic compilation
- The code written in IronPython is capable of communicating with .NET objects
- Just like Jython, IronPython is a bridge between the .NET universe and the Java universe
The advantage with IronPython is that existing .NET developers can make use of this implementation of Python for developing quick expressive scripts with least set up which can be used in embedding, testing or simply automating a command-task. We can make use of IronPython for one of the interesting projects like constructing an embedded web server within an application which can be developed with one of the available Python web frameworks. It is much easier and faster to develop for than hosting an ASP.NET web server within our app.
Note that the IronPython is licensed under the Microsoft Public License.
Stackless Python is simply an upgraded version of the default Python programming language with an added benefit of micro-threads. It saves a programmer from the headache of the complexity and unreadable code that comes with multi-thread programming.
The concepts related to threads is complex and now, Micro-threads?! Well, I will try to put it very simply. Micro-threading is a software-based threading model where very small and lightweight threads are created inside of multi-core processors. Each of the core in the system is assigned two or more small threads which use the core in its idle time with a blazingly fast context switch. Here are some few quick points about Stackless Python:
- Even with added thread programming, easily readable code is still possible
- Program’s performance increases without much memory consumption due to threads being tiny
- It also enhances functional programming as the microthreads needs to be defined as tasklets which is code wrapped inside functions which is launched as microthreads
Stackless is not just about threads. It also provides smart communication between the tasklets (microthreads), a round-robin algorithm to help them schedule monitors & resources and serialization facility as well. The defined tasklets have a big advantage that even if you completely remove Stackless from your usage, you don’t have to make any change in the code because tasklets are after all, simple Python functions.
ActivePython is an enterprise distribution of the Python programming language with a lot of additional packages available by default. A lot more integrations have been done in ActivePython to make it a true enterprise distribution. Some of these are:
- ActivePython comes with integrated Intel Math Kernel Library (MKL) which speeds up Machine Learning programs written with ActivePython and using NumPy, SciPy, Matplotlib, and theano.
- Above advantage is available only when the developed programs are run on Intel-based hardware only
- Packages like Tensorflow, Keras, NumPy, HDFS (for manipulating & storing data) comes integrated with ActivePython
ActivePython also claims that it has reduced a lot of security risks present in different packages by making sure that each of the packages remains at the latest version and all security patches are timely installed. Also, it is 100% compatible with the open source version of Python and provides a commercial touch on top of that. Although ActivePython sounds so good, please note that most of its features come only with a commercial version of the distribution. For this, you will need to upgrade your library to a paid version.
As ActivePython is enterprise in nature with a community version available for free, experts are available to answer all queries you might have with its efficient usage. You can have a look at the different type of licenses available with ActivePython here. As ActivePython is paid in nature and not all of its features might be required at all times, you might have to spend some hard time in convincing the senior management to buy a paid version of a distribution whose free and open-source version is readily available with so much community support.
- There is a module PyJS Desktop as well. It allows running exactly the same Python web application source code as a standalone desktop app (running under Python) instead of a Web browser
- Most of the Unix-systems now comes preinstalled with PyJS and PyJS Desktop versions
- PyJS makes use of Python’s abstract syntax tree to generate equivalent JS code
- Even though a lot of data-types are similar in Python and JS, some of the Python data types are converted to custom objects. Like Python’s lists are converted to custom JS objects so that functions of the datatypes can be implemented, like append function with Python’s list
The good thing about PyJS is that it is very light in nature, can be used from the web browser directly and programs can be executed from a web browser JS console.
Nuitka is an excellent Python compiler which takes Python code and compiles it to C/C++ executables or the source code. Here are some few quick points about Nuitka:
- Nuitka’s last stable version was released on October 2017
- The biggest advantage with Nuitka is that even if you cannot run Python on your machine, you can still install Nuitka and create standalone programs with Nuitka
- Nuitka is written purely in Python itself and is completely compatible with Python 2.6, 2.7, 3.3, 3.4, 3.5, 3.6, and 3.7
- Another advantage is that we can use all Python library modules and all extension modules freely
- Please note that the supported Operating Systems include Linux, FreeBSD, NetBSD, macOS X, and Windows (32/64 bits). Other OS might not work.
It is to be noted that we need at least the C11 C compiler for C++. Many other code editors can be used, like Visual Studio 2017 but they are not officially supported. Nuitka is even available with Anaconda if you prefer it for your development, especially in the field of Data Science and Machine Learning. Nuitka is licensed under the Apache License, Version 2.0.
Shed Skin is a Python compiler used to convert the statically typed Python program into C++. By statically typed we mean that the variables being used in the system should only infer to a single datatype. Also, some common features are not available which includes the usage of nested functions and defining functions which accept a variable number of arguments. Also, only some of the standard library functions are available to be used. Here are some few quick points about Shed Skin:
- Shed Skin is just an experimental compiler to translate statically typed programs into C++ code with various limitations
- Not all Python features are available to be used. This means that is you use an unsupported module, you will have to remove it, add plain code which performs the same functionality on your own
- The Shed Skin also doesn’t scale very well beyond a few thousand lines of code
As the Shed Skin is still an experimental library, it can improve a lot and you can face some basic bugs during its usage. There are some typing restrictions and not all modules are supported as of now.
Some of the Python performance boost in Shed Skin comes from the fact that Shed Skin has reimplemented the Python built-in types into its own set of classes implemented in C++. There are similar interfaces to their Python counterparts.
To simply state, Skulpt is just an in-browser implementation of Python. This means that no processing or plugins are needed to run Python in a web browser. Any code we write is completely executed in a web browser. This means that if you want to make a web application which is capable of providing the users the facility to run Python programs in the browser and still keep your background servers secure, Skulpt is a good way to go.
Skulpt allows us to:
- Embed skulpt into an existing webpage or blog
- Add skulpt directly to your HTML for a custom integration
- For even more control, teach Skulpt to import your own custom modules
As the name suggests, WinPython is a Python distribution created specifically for Microsoft Windows Operating system. WinPython was designed as the earlier versions of CPython were not well designed for Windows and provided too many bugs. Although the CPython is highly stable now but there are a lot of features in WinPython which are not present in CPython. Here are some few quick points about WinPython:
- WinPython is a self-contained distribution for Python. This means that you don’t even need to install WinPython but just download and unpack it in a Windows directory and it will start working for you
- This is a big advantage as many times, we do not have enough privileges to install some softwares in a system
- WinPython also comes packages with some of the Data Science and Machine Learning related packages like NumPy, Pandas, SciPy, Matplotlib, etc. This means that these modules can be used straight away
- WinPython also contains a bundled C and C++ compiler as a lot of Windows-based machines do not have one
Although, WinPython sounds ver good, one limitation for the same is that it comes bundled with a lot of features, out of which many might not be needed at all times. These packages and features are not optional to download and use. Although, there exist a zero package which contains just the minimal Python compiler and nothing else.
Although JVM is considered to be a decent and well-optimized virtual machine, Jython usually suffers from a loss than CPython when it comes to establishing parameters for performance. There are various factors which lead to this decreased in performance in Jython, such as:
- Jython does not make use of reference counting. This means that resources are released as they are garbage collected. IN an equivalent CPython program, this happens much earlier and so, a lighter liner of execution
- Jython was meant to be a bridge between Java and Python and performance was not in focus when Jython was developed
Note that although JPython brings Python to the Java Virtual Machine, it doesn’t bring Python to Android mobile app development, which could have been a big advantage for it.
CPython seriously lacks some of the optimisations for Performance found in other Python distributions. In CPython, there is no Just in Time compilation available, no accelerated math libraries and no third-party integrations to provide a performance boost. This means that all of these things are completely left on the developer to complete but sometimes, this can prove to be very limited as there is only so much a developer can do.