IronPython is an implementation of the Python programming language targeting the .NET Framework and Mono. IronPython is written entirely in C#, although some of its code is automatically generated by a code generator written in Python. IronPython is implemented on top of the Dynamic Language Runtime (DLR), a library running on top of the Common Language Infrastructure that provides dynamic typing and dynamic method dispatch, among other things, for dynamic languages. The DLR is part of the .NET Framework 4.0 and is also a part of Mono since version 2.4 from 2009. The DLR can also be used as a library on older CLI implementations.
The performance characteristics of IronPython compared to CPython, the reference implementation of Python, depends on the exact benchmark used. IronPython performs worse than CPython on most benchmarks taken with the PyStone script but better on other benchmarks. IronPython may perform better in Python programs that use threads or multiple cores, as it has a JIT, and also because it doesn’t have the Global Interpreter Lock (GIL), a mechanism used in computer-language interpreters to synchronize the execution of threads so that only one native thread can execute at a time. An interpreter that uses GIL always allows exactly one thread to execute at a time, even if run on a multi-core processor. Some popular interpreters that have GIL are CPython and Ruby MRI.
IronPython is an excellent addition to the .NET Framework, providing Python developers with the power of the .NET framework. Existing .NET developers can also use IronPython as a fast and expressive scripting language for embedding, testing, or writing a new application from scratch.
The CLR is a great platform for creating programming languages, and the DLR makes it all the better for dynamic languages. Also, the .NET framework (base class library, presentation foundation, Silverlight, etc.) gives developers an amazing amount of functionality and power.
Installing IronPython in Linux
Installing IronPython is quite easy. Go to mono-project:
- Add the Mono repository to your system (Ubuntu based distro):
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF $ echo "deb https://download.mono-project.com/repo/ubuntu stable-bionic main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list $ sudo apt update
- Install Mono
$ sudo apt install mono-devel
- Install Numerics
$ sudo apt install libmono-system-numerics4.0-cil
$ ipy -V david@david-Latitude-5480 IronPython 2.7.9 188.8.131.52 on 184.108.40.206 (tarball Thu Oct 4 10:20:38 UTC 2018) ------------------------------------------------------------ $ ipy IronPython 2.7.9 (220.127.116.11) on Mono 4.0.30319.42000 (64-bit) Type "help", "copyright", "credits" or "license" for more information. >>>
Installing IronPython in MacOSX
First, go to https://www.mono-project.com/download/stable/ and download the latest release and then install it; now, download IronPython from here: https://github.com/IronLanguages/ironpython2/releases and install the .pkg file.
Easy, right? But wait, we’ll need a final step…
Open your terminal and locate the
$ which ipy /Library/Frameworks/Mono.framework/Versions/Current/Commands/ipy
The file should be something like this:
#!/bin/sh export IRONPYTHONPATH=/Library/Frameworks/IronPython.framework/Versions/2.7.9/ exec /Library/Frameworks/Mono.framework/Versions/5.16.0/bin/mono /Library/Frameworks/IronPython.framework/Versions/2.7.9/bin/ipy.exe "$@"
Same with ipyw:
#!/bin/sh export IRONPYTHONPATH=/Library/Frameworks/IronPython.framework/Versions/2.7.9/ exec /Library/Frameworks/Mono.framework/Versions/5.16.0/bin/mono /Library/Frameworks/IronPython.framework/Versions/2.7.9/bin/ipyw.exe "$@"
Installing IronPython in Windows
Download the .msi file from: https://github.com/IronLanguages/ironpython2/releases and install it. Done.