1

We have a big C# application, would like to include an application written in python and cython inside the C#

Operating system: Win 10 Python: 2.7 .NET: 4.5+

I am looking at various options for implementation here. (1) pythonnet - embed the python inside the C# application, if I have abc.py and inside the C#, while the abc.py has a line of "import numpy", does it know how to include all python's dependencies inside C#?

(2) Convert the python into .dll - Correct me if i am wrong, this seems to be an headache to include all python files and libraries inside clr.CompileModules. Is there any automatically solution? (and clr seems to be the only solution i have found so far for building dll from python.

(3) Convert .exe to .dll for C# - I do not know if i can do that, all i have is the abc.exe constructed by pyinstaller

(4) shared memory seems to be another option, but the setup will be more complicated and more unstable? (because one more component needs to be taken care of?)

(5) Messaging - zeromq may be a candidate for that.

Requirements: Both C# and python have a lot of classes and objects and they need to be persistent C# application need to interact with Python Application They run in real-time, so performance for communication does matter, in milliseconds space.

I believe someone should have been through a similar situation and I am looking for advice to find the best suitable solution, as well as pros and cons for above solution. Stability comes first, then the less complex solution the better it is.

mcsy
  • 43
  • 6
  • This question is not a good candidate for S.O. Check this: https://ironpython.net/ – Gusman Jun 11 '20 at 07:16
  • Thanks Gusman, i did try ironpython but it encounters a problem that some of the python libraries such as numpy are not supported by Ironpython. As such, it is already removed from my list – mcsy Jun 11 '20 at 09:43
  • I am having a similar issue ... need to pass a bunch of variables from C# to python, I know technically shared memory would work... but before that I would like to seek for simple solution which allows me to call python method in C# seamlessly just like I am calling another C# method (or does it not exist??) I am still researching... let me know if you find any good ways! – Cheung Chi Hin Jun 11 '20 at 15:20

1 Answers1

0

For variant 1: in my TensorFlow binding I simply add the content of a conda environment to a NuGet package. Then you just have to point Python.NET to use that environment instead of the system Python installation.

LOST
  • 2,956
  • 3
  • 25
  • 40