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

0

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?

python
c#
keras
azure-service-fabric
python.net
asked on Stack Overflow Oct 8, 2020 by Sebastian

1 Answer

0

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.

answered on Stack Overflow Oct 9, 2020 by LoekD

User contributions licensed under CC BY-SA 3.0