Question

I've been banging my head for the past two days trying to find out if it's possible to run a python module in C#. The module I'm interested in is Sympy which can be found here http://code.google.com/p/sympy/ (in case anyone's interested). It's a math library, and this one does what I need it to do. I haven't found a C# library which is as good (I tested math.net and others..)

From searching google I found out that you can execute python code inside C# using IronPython. Haven't found any real good example of using a module with IronPython or with PythonNet.

Can anyone tell me if it's possible to use a python module in C# and what would he recommend IronPython or PythonNet. Also if it's possible, does it mean my APP will need the python compiler installed to work or will the referenced dll be enough?

Was it helpful?

Solution

I don't know how well loading a python lib in c# will do ya, but I'd write my program via IronPython.

you can then compile it to an exe so your users don't know the difference.

now this is guesswork, but maybe you can then load your assembly in other c# projects and use it that way. i.e. wrap the python library with ironpython and then load that in c#

its not elegant, but it'll work, I bet.

OTHER TIPS

I know its an old question, but it might help someone :)

So you can place your python script into your Anaconda3\Lib\site-packages folder and using the pythonnet example in their wiki page:

static void Main(string[] args)
{
    using (Py.GIL())
    {
        dynamic foo = Py.Import("your_script_name");
    }
}

And the referenced dll should do the work. And for Iron Python i think it's only supported for python 2.x and it's not managed any longer by the authors so that might be a bit complicated. Also you may want to pay attention on your IIS threading issue for Python GIL, it might become a huge pain after a while.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top