5

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?

4
  • What versions of Iron Python are you using? What CLR? Commented Feb 14, 2013 at 23:52
  • I'm still using my own math (mostly 4x4 matrices) for the portion that is numerical. Just using C# (.Net 4.0) for now. I'd be flexible for ease of deployment, since I'm not using any advanced C# features. Commented Feb 15, 2013 at 0:54
  • 1
    The dlr is already installed with .net 4. So you won't have to install that. You can usually just dump the IronPython assemblies and your custom assemblies in that case. I don't know about numpy - you'll have to check with them. Commented Feb 15, 2013 at 0:57
  • 1
    IronPython also needed the Python stdlib last time I checked. Commented Feb 15, 2013 at 1:38

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

These are great news! Can you also import these modules from a host application running Microsoft.Scripting? Will you be sharing these DLLs somewhere? It would be great if the process of doing this could be documented, so we could continue the footsteps started by the Enthought distribution so long ago. Thanks!
Um I have no idea about Microsoft Scripting. But I am happy to share the DLLs on Github. Will take me a few days, then I'll post the link here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.