TLDR: How do I run pythonnet in a Microsoft Service Fabric Application?
I want to use Keras.Net to run Python-trained ML models in C#, but I have problems doing this in a Service Fabric application. I am running a Service Fabric Local Cluster on my host machine. I have also installed python on this host machine. Running Keras.Net code in a C# Console application on host machine seems to work fine, but running the same code in a SF Application on host machine I get the following error:
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)
It seems like a simple Path issue, But I have checked that the Environment holds the same values in the C# Console app as well as the SF Application (when debugging in visual studio).
Am I taking the wrong approach here? Can the SF Cluster Node access the python installation on the host machine?
I recommend using a Docker container to package your application together with its prerequisites, so it runs on just about any host able to run containers.
This way, if it works on your machine, it'll also work on a hosted cluster. It would also prevent the need to install tooling on nodes, making them more like 'cattle' instead of 'pets'.
More info here.
Since a Service Fabric Local Cluster runs a virtual cluser on the host machine, installing software on the host machines does not automatically mean the nodes in the virtual cluser has access to them.
In order to run Python on SF it has to be installed on the nodes of the cluster themselves. https://stackoverflow.com/a/43819415/6055533 demonstrates how to do this.
With this being said, I would follow the recommendations by @LoekD (https://stackoverflow.com/a/64275346/6055533) of containerizing.
User contributions licensed under CC BY-SA 3.0