Infer.NET and IronPython on Ubuntu 12.04Posted: August 5, 2012
This post is to help understand how to get Infer.NET working on Linux, specifically Ubuntu 12.04. All this stuff was found by Binging around a bit, so big thank you to the collective group I got this from. Most helpful was a post put together a couple years ago.
To start off you need Mono, an open source .NET framework for IronPython to be built on. Right now Mono is on version 2.10.x
That’s as simple as:
sudo apt-get install mono-complete
There doesn’t look like there is an IronPython package in the Ubuntu repositories, so let’s get the source from Github. As of this writing, the current release is 2.7.x. Make sure to put it in an appropriate folder.
git clone git://github.com/IronLanguages/main.git IronLanguages
Ok now we need to build our IronPython on Mono. It looks like their is no need to specify the Mono specific solution file anymore, so just use the standard solution file:
xbuild Solutions/IronPython.sln /p:Configuration=Release
Now we have IronPython working. Check this by getting into the executables folder:
I received an error with importing the OS module, but after digging around I found the module that seems to do the trick. It’s easiest to automatically export the path to this OS module in our Bash profile so we don’t have to manually import the path. Thus, put this statement in your Bash profile in ~/.bashrc:
export IRONPYTHONPATH= $IRON_LANGUAGES_INSTALLATION_PATH/IronLanguages/External.LCA_RESTRICTED/Languages/IronPython/27/Lib:$IRONPYTHONPATH
While we are in our bashrc, let’s create an alias to make it easier to invoke IronPython. It should look something like this and also should be in ~/.bashrc
alias ipy=”mono $IRONPYTHON INSTALLATION DIRECTORY/IronLanguages/bin/Release/ipy.exe”
Now get Wine so we can install Infer.NET, to do this first add their team’s repository to your sources:
sudo add-apt-repository ppa:ubuntu-wine/ppa
and refresh with:
sudo apt-get update
now install Wine, WE WANT VERSION 1.4 even though the current version is 1.5, with:
sudo apt-get install wine1.4
The reason we want Wine 1.4 is because 1.5 does not support msiexec, which is what we need to open the microsoft installer package put together by the Infer.NET team at Microsoft Research .
And click on it to open it with Wine 1.4. Alternatively open it using the terminal with:
msiexec /i <Infer.NET package name>
Now when this installs, you have Infer.NET! To get the right libraries to use it in the future, we need to append the directory where all the .dll and such are located to our IronPython sys.path. That sys.path will look something like:
$YOUR HOME FOLDER/.wine/dosdevices/c:/Program Files/Microsoft Research/Infer.NET 2.4 Beta/bin/Release
OK so now everything is ready to go…but wait, we have problems when importing classes from the Distribution namespace. This seems to only be a problem with IronPython/Mono on Linux as it has been tested with Mono on Windows and all was gravy. Well no worries, we just need to be explicit when importing our distributions. Please see this post from the very helpful creators of Infer.NET on their forum.
Let’s refer to the very helpful tutorials and API documentation on the Infer.NET website itself for writing our IronPython scripts itself. But how do we run them?
Well that’s a simple as invoking the regular Python (CPython runtime), but instead using our newly aliased “ipy” command.
Alternatively, if you would like to compile this to an executable using the instruction set .NET uses, we need to invoke the script pyc.py along with some flags:
ipy $IRON_PYTHON_INSTALL_PATH/IronPython/Public/Tools/Scripts/pyc.py /target:exe /main:./<our_IronPython_script_name>.py /standalone
note that omitting that last part “/standalone” will create an .exe AND .dll file instead of packaging them together.
That should be it, I hope it worked for you too!