如何在Service Fabric应用程序中运行pythonnetKeras.Net?

问题描述

TLDR:如何在Microsoft Service Fabric应用程序中运行pythonnet

我想使用Keras.Net在C#中运行经过Python训练的ML模型,但是在Service Fabric应用程序中执行此操作时遇到问题。我在主机上运行Service Fabric本地群集。我还在此主机上安装了python。在主机上的C#控制台应用程序中运行Keras.Net代码似乎可以正常工作,但是在主机上的SF应用程序中运行相同的代码,我得到以下错误

System.AggregateException: One or more errors occurred. (One or more errors occurred. (Unable to load DLL 
'python38' or one of its dependencies: The specified module Could not be found. (0x8007007E)))
---> System.AggregateException: One or more errors occurred. (Unable to load DLL 'python38' or one of its dependencies: The specified module Could not be found. (0x8007007E))
---> System.DllNotFoundException: Unable to load DLL 'python38' or one of its dependencies: The specified module Could not be found. (0x8007007E)
    at Python.Runtime.Runtime.Py_IsInitialized()
    at Python.Runtime.Runtime.Initialize(Boolean initSigs)
    at Python.Runtime.PythonEngine.Initialize(IEnumerable1 args,Boolean setSysArgv,Boolean initSigs)
    at Python.Runtime.PythonEngine.Initialize(Boolean setSysArgv,Boolean initSigs)
    at Python.Runtime.PythonEngine.Initialize()
    at Keras.Keras.InstallAndImport(String module)
    at Keras.Keras.c.b__27_0()
    at System.Lazy1.ViaFactory(LazyThreadSafetyMode mode)
    at System.Lazy1.ExecutionAndPublication(LazyHelper executionAndPublication,Boolean useDefaultConstructor)
    at System.Lazy1.CreateValue()
    at System.Lazy1.get_Value()
    at Keras.Keras.get_Instance()
    at Keras.Models.BaseModel.ModelFromJson(String json_string)

这似乎是一个简单的Path问题,但是我检查了环境在C#Console应用程序和SF Application(在Visual Studio中调试时)是否具有相同的值。

在这里采用错误方法吗? SF群集节点可以访问主机上的python安装吗?

解决方法

我建议使用Docker容器将应用程序及其先决条件打包在一起,因此它几乎可以在任何能够运行容器的主机上运行。

这样,如果它可以在您的计算机上运行,​​它也可以在托管集群上运行。这也将避免在节点上安装工具的需要,从而使它们更像是“牛”而不是“ pets”。

更多信息here

,

由于 Service Fabric 本地群集在主机上运行虚拟集群,因此在主机上安装软件并不自动意味着虚拟集群中的节点可以访问它们。

为了在 SF 上运行 Python,它必须安装在集群本身的节点上。 https://stackoverflow.com/a/43819415/6055533 演示了如何执行此操作。

话虽如此,我将遵循@LoekD (https://stackoverflow.com/a/64275346/6055533) 的容器化建议。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...