Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running CPython functions from C#

Tags:

python

c#

.net

I'm working on a project where I need to be able to run a python function that depends on SciPy/NumPy. Due to this being an add-on to a project already in progress, using IronPython would not be an option.

Additional info:

  • Python.NET seemed to be a good fit, but I was unable to get the return value from RunString() (it would only return NULL).
  • Passing arguments and catching the return value (a tuple) is necessary.
  • The function is in a statistical package that was created by a support group for the team, so modification of that would also not be possible.

I'm at quite a loss for what to do. Any hints in the right direction are appreciated. Thanks for any help you can give!

I understand that this may be quite vague, but I cannot give explicit details to the project. If any clarification is needed please let me know and I'll do my best!

like image 393
Eonxre Avatar asked Oct 27 '25 12:10

Eonxre


1 Answers

I guess you could write a DLL that uses the CPython API to expose the function, then call it in C#? It's possible to embed the Python interpreter; although I've never done this personally, I guess it would be useful: http://docs.python.org/extending/embedding.html

like image 194
Bastien Léonard Avatar answered Oct 30 '25 03:10

Bastien Léonard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!