簡體   English   中英

如何在 Service Fabric 應用程序中運行 pythonnet (Keras.Net)?

[英]How do I run pythonnet (Keras.Net) in a Service Fabric Application?

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)

這似乎是一個簡單的路徑問題,但我已經檢查過環境在 C# 控制台應用程序和 SF 應用程序中具有相同的值(在 Visual Studio 中調試時)。

我在這里采取了錯誤的方法嗎? SF集群節點可以訪問宿主機上的python安裝嗎?

我建議使用 Docker 容器將您的應用程序與其先決條件打包在一起,因此它幾乎可以在任何能夠運行容器的主機上運行。

這樣,如果它適用於您的機器,它也適用於托管集群。 它還可以防止需要在節點上安裝工具,使它們更像“牛”而不是“ 寵物”。

更多信息在這里

由於 Service Fabric 本地群集在主機上運行虛擬集群,因此在主機上安裝軟件並不自動意味着虛擬集群中的節點可以訪問它們。

為了在 SF 上運行 Python,它必須安裝在集群本身的節點上。 https://stackoverflow.com/a/43819415/6055533演示了如何執行此操作。

話雖如此,我將遵循@LoekD ( https://stackoverflow.com/a/64275346/6055533 ) 的容器化建議。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM