简体   繁体   English

C# 和 Python 应用程序之间交互的替代方案——Pytho.net vs DLL vs shared memory vs messaging

[英]Alternatives for interaction between C# and Python application -- Pythonnet vs DLL vs shared memory vs messaging

We have a big C# application, would like to include an application written in python and cython inside the C#我们有一个很大的 C# 应用程序,想在 C# 中包含一个用 python 和 cython 编写的应用程序

Operating system: Win 10 Python: 2.7 .NET: 4.5+操作系统:Win 10 Python:2.7 .NET:4.5+

I am looking at various options for implementation here.我在这里查看各种实施选项。 (1) pytho.net - 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#? (1) pytho.net - 将 python 嵌入到 C# 应用程序中,如果我有 abc.py 并且在 C# 中,而 abc.py 有一行“import numpy”,它是否知道如何在其中包含所有 python 的依赖项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. (2) 将 python 转换为 .dll - 如果我错了请纠正我,将所有 python 文件和库包含在 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. (而且 clr 似乎是迄今为止我找到的从 python 构建 dll 的唯一解决方案。

(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 (3) Convert.exe to.dll for C# - 我不知道我能不能做到这一点,我只有 pyinstaller 构建的 abc.exe

(4) shared memory seems to be another option, but the setup will be more complicated and more unstable? (4) shared memory 好像是另一种选择,但是设置会不会更复杂,更不稳定? (because one more component needs to be taken care of?) (因为还需要处理一个组件?)

(5) Messaging - zeromq may be a candidate for that. (5) 消息——zeromq 可能是一个候选者。

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.要求: C# 和 python 都有很多类和对象,它们需要持久化 C# 应用程序需要与 Python 应用程序交互 它们实时运行,因此通信性能很重要,以毫秒为单位。

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.稳定性是第一位的,然后是越不复杂的解决方案越好。

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.对于变体 1:在我的 TensorFlow 绑定中,我只是将 conda 环境的内容添加到 NuGet package。然后您只需指向 Python.NET 使用该环境而不是系统 Python 安装。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM