Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to deploy a C# application that calls numpy through IronPython

I'm writing a C# GUI application where I'd like to use numpy, which I have used under Python 2.7 extensively and which is very fast and easy to program. (I still find the GUI work in C# much easier to use than PyQt.)

An IronPython port of numpy and scipy exists now and I'd like to learn how to use it.

Before starting, I'd like to know what kind of deployment options I will have? Can I fully wrap python and numpy or do I have to install python, Ironpython, numpy on my customer's machines?

like image 612
roadrunner66 Avatar asked Nov 04 '22 04:11

roadrunner66


1 Answers

You can wrap Ironpython code to a .net assembly as a DLL or exe. If you need to load the code from other .NET code, create a DLL using an IronPython script

import clr
clr.CompileModules(dllname, module1.py, module2.py,...)

then load that assembly with

Assembly dpma = Assembly.LoadFile(Path.GetFullPath("CompiledIronPythonModule.dll"));
pyEngine.Runtime.LoadAssembly(dpma);

(C# example). In VisualStudio you will need references to IronPython and the dll in the project.

I just succeeded in compiling numpy and scipy-refactored from scratch with IronPython 2.7.5, Visual Studio 2012 .NET 4.0 with Intel Fortran Composer XE 2013 (using the latter needed some changes to the scipy iron_setup.py files). The output are a set of DLLs. I can at this point import the modules on the IronPython command line. What's not working yet is how to cook IronPython code with a numpy/scipy import into a .net assembly. For this, I will be checking into ironpycompiler.

like image 117
Sven Avatar answered Nov 14 '22 07:11

Sven