c# application calling Scipy

sturlamolden sturlamolden at yahoo.no
Sun Jan 7 12:16:09 EST 2007


dongarbage at hotmail.com wrote:
> Hi,
>
> Novice here. :)
>
> I'm building a c# application and I want to call functions in SciPy
> from that application.
>
> What's the best way to call SciPy methods from a C# program?

You need to:

1. Embed a Python interpreter in your C# app. That is, importing from a
DLL with a Python interpreter and defining a few structs.

2. Define a NumPy ndarray as a C# struct.

Or:

1. Write a proxy DLL in C and embed Python in that. This is the
preferred way, as I see it. You are relieved of having to redefine
Python and NumPy's C structs in C#.

2. Import your proxy in C# and marshal a C# array to a IntPtr. That
will allow you to map a C# array to a NumPy ndarray C struct in your
proxy.

The latter method is less hassle.

In any case you also need to make sure you are using a .NET runtime
that are linked to the same CRT as Python (.NET 1.1 should work).

Using IronPython will not work, as neither NumPy nor SciPy is ported to
IronPython (and porting is not trivial either; but if you take the task
upon yourself, many will be happy if you succeeed.)




More information about the Python-list mailing list