I have written a post method in .NET that uses the Pythonnet to solve an optimization problem. It works fine on the Debug Mode in Swagger, but when deployed on the IIS shows Error. Following is the the method being Called
public Dictionary<string, double> Fertilizerddt(List<double> Ncomp, List<double> Pcomp, List<double> Kcomp, List<double> Required, List<string> chemicalNames)
{
if (!PythonEngine.IsInitialized)
{
Runtime.PythonDLL = @"C:\Users\Administrator\AppData\Local\Programs\Python\Python310\python310.dll";
PythonEngine.Initialize();
PythonEngine.BeginAllowThreads();
}
using (Py.GIL())
{
dynamic sys = Py.Import("sys");
sys.path.append("");
string code = """
import numpy as np
from scipy.optimize import linprog
def optimize(chemical_names, *chemical_compositions, N_required=20, P_required=20, K_required=20):
#Processing
return result_dict, total_quantity
""";
dynamic optimize = PyModule.FromString("testImport", code);\
return finalResult;
}
}
Now when I comment out the complete pythonnet part, the post method does work. I have been trying a lot but could not find anything on this. Please it'll be great if anyone can guide me in this regard.