Why IronPython is shit…


I’m not a C# fan, I’m more a python fan though. Anyway. At work I had to make C# be able to call python functions. So I started googling. I found some nice posts from:

Run python from C# and vice versa

But thanks to .Net 4.0 It seems that a lot of troubles have been resolved introducing the new dynamic type in C#. With that type I can finally do some work in python then export any class to my C# world.

There are still some issues in using any python module: Ironpython is not compatible with the normal python interpreter, or CPython. You can use Ironclad to make Ironpython run C CPython modules but they don’t support Python 2.7 yet and the last update from their release is from  07/2010.

Install IronPython

After installing IronPath you have to modify windows PATH system variable such that you can execute ipy in a shell and get a IronPython console. To do so you have to add the following two lines at the end of your PATH variable on Windows:

;c:Program Files (x86)IronPython 2.7;c:Program Files (x86)IronPython 2.7Sciprts

Install Setuptools

Tried to install distribute. Of course it didn’t work. It crashed. I’ve successfully managed to setup setuptools but their support is broken and i’m unable to install simple python eggs due to multiple error.   These are the steps that I’ve followed

c:UsersvinzDesktop>ipy distribute_setup.py
Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.2
Extracting in c:usersvinzappdatalocaltemptmpanru2x
Now working in c:usersvinzappdatalocaltemptmpanru2xdistribute-0.6.27
Installing Distribute

Process is terminated due to StackOverflowException.
Something went wrong during the installation.
See the error message above.

Use setuptools instead http://peak.telecommunity.com/dist/ez_setup.py

Open a priviledged shell http://www.howtogeek.com/howto/windows-vista/run-a-command-as-administrator-from-the-windows-vista-run-box/

ipy ez_setup.py

Since there is no support to zlib in ironpython you cannot install any egg anyway even if you installed setuptools.

Install an egg

I’ve managed to install setuptools, however installing a simple package fails because .pth files are not managed correctly. So the best way of installing eggs is just to take their source, maybe unpacking an egg since it’s just a zip file, and copy directly on the IronPython site-packages directory. I’ll still describe the process I did just in case some reader sees that I’ve done a mistake.

To install an egg, just unzip it and run:

ipy -X:Frames setup.py install --user

The –user will install the package for user only. To install the package system-wide you have to install from an administrator shell.

The best thing to do to install an egg is just to unpack it, it’s a zip file, then copy the directory of your library in C:Program Files (x86)IronPython 2.7Libsite-packages . That directory will be included in sys.path of every ipy interpreter.

First problems

Just run a first example which uses ElementTree and i got:

NotImplementedError: iterparse is not supported on IronPython. (CP #31923)

Surfing a bit the web I found that It’s a bug from Dec 2011 http://ironpython.codeplex.com/workitem/31579

So I’ve downloaded and installed elementTree, It will install on normal Python’s site-packages, so you have to move the folder unver IronPython’s site-packages. After doing so, when you need to import etree just do:

import platform
if platform.python_implementation() == 'IronPython':
from elementtree import ElementTree
import xml.etree.ElementTree

This code will import the just installed elementtree library or the system library one depending if you are on normal Python interpreter (CPython) or IronPython.


From this experience I’ve learnt many things:

  • IronPython is not a full python interpreter: it lacks many basic support like the one for setuptool and distribute
  • IronPython is very bugged, even the standard library is bugger. Thus import as external module everything you need.
  • IronPython cannot use the vast majority of python modules because to support .NET jit it breaks CPython compatibility

Thus. Keep away from it! It’s just crap. Microsoft’s dream of .Net simply doesn’t work for python. Yeah, you can access Python functions and class from C# but you miss the goal that makes people use python: a very huge amount of libraries and packages that are easy to install and integrate. Sorry Microsoft, it’s yet another #Fail

How to quickly share a git repository
How to install pymatlab
  • Sorry to hear about your problems, but this has not been my experience at all.

    IronPython is obviously going to have issues with extensions written in C, but those are platform-specific hacks anyway. Witness the problems of getting or compiling the right version of a particular extension for windows, when CPython dev mostly happens in the Linux world.

    The point of IronPython is to have a modern dynamic language that can access (and be accessed from) the whole of the CLR-based ecosystem. My experience of this is very much the same as I’ve had with CPython. Stuff (i.e. .Net stuff) just works, first time, and the development experience is a joy.

    As an example: I use WSDL.exe to create proxy stubs to the millions of SOA endpoints out there. Compile them into dlls with the C# compiler (CSC) and import them into IronPython for easy Web Service access. Try that in CPython with the the hopelessly incomplete SOA projects such as Suds et al.!

  • omg i am like the opposite you’d hate me. As much as I like python it’s uses for me are a bit limited (unix admin?), so I can now embed python in an app potentially as the scripting language. I am at the moment actually trying to figure out how a game like MTG online works, I recon the cards themselves may have a script code when I tackle this sort of complexity.

    so I really see the value in embedded python, if anything now I will need to figure how possibly I can make the python do less so players do not hyjack the game xD

    say what anyone will about any what language I think many people really appreciate python to, you could make people use javascript after all!

    • The article is just on IronPython, the M$ implementation of the interpreter. I use python (CPython) regularly and never had this kind of problems

      • what i mean is i like iron python because it’s an option to embed python.. that said i haven’t yet had a chance to get annoyed by it so I am not yet able to judge.

        further down the line though, it looks like a better option (ironpython) for my needs vs compiling c# on the fly which i think is the only way to it.

        From my perspective having iron python in .net means I might use it in a “real program”, because python is great for stuff for yourself, or install apps on unix, but unless you embed it, it never reaches an end user. I say all this and I do think of Blender, I think though it’s some compiled core running embedded python

        basically anyway cpython never reaches end users beyond programming enthusiasts and academics using things like scipy, so it’s great it’s reliable but it’s not like I can use it anyway…. so I was hoping actually that .net python would be the defacto deployment python actually (and that maybe it would be defacto to deploy python)

Leave a Reply

%d bloggers like this: