1. Introduction

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.

 

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:

  • CPython
  • IronPython
  • ActivePython
  • Jython
  • PyJS
  • Stackless Python
  • Nuitka
  • Shed Skin
  • Skulpt
  • WinPython

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.

2. Python Compilers and Interpreters

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.

2.1 CPython

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 classes

Python 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.

2.2 Jython

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.

2.3 IronPython

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.

2.4 Stackless Python

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.

2.5 ActivePython

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.

2.6 PyJS

Just like it sounds, PyJS is a boon for web developers who want to write simple Python code and execute it in web browsers, just like Javascript. PyJS is a Python to Javascript translator which translates the written Python code into its Javascript equivalent so that the program can be run on a web browser. Not just that, PyJS comes with an AJAX framework whose responsibility is to handle the gaps between the JS and the DOM support of various web browsers. Here are some few quick points about PyJS:

  • 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 Javascript developers can design and write their apps in a pure object-oriented paradigm as they can embed Python code in the JS code. This means there is runtime support for runtime errors as well.

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.

2.7 Nuitka

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.

2.8 Shed Skin

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.

2.9 Skulpt

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

Please note that Skulpt is another compiler which compiles Python into Javascript itself. But this doesn’t mean that you can run JS in Skulpt. As Python is made to run in all OS and Javascript is designed to run in the web browsers, Skulpt provides a genuine environment where the compiled code is executed in Javascript form.

Finally, Skulpt Python interpreter is itself written in Javascript and is released under the MIT License.

2.10 WinPython

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.

3. JPython vs CPython

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.

4. Conclusion – Python Compilers and Interpreters

In this lesson, we looked at some interesting Python compilers, distributions and interpreters. When I started writing this lesson, even I was amazed related to the type of distributions and translators available for Python programming language. All these Python compilers, translators and interpreters informs us that Python is not just limited to CPython, the default implementation but with the right set of tools in the pocket, it can be executed and translated into C, C++, Javascript as well.

Although C and C++ don’t sound like a big surprise, Javascript compatibility was big learning, even for me. The idea of it being even possible was a great thing which even I learned while contributing to this lesson. Another great example we learned was regarding the WinPython compiler which is available for Windows OS. There aren’t a lot of packages which are made specifically for Windows only. I hope you enjoyed this lesson on Python Compilers and Interpreters.