I am trying to import a script as follows:
Runtime.PythonDLL = "python311.dll";
PythonEngine.Initialize();
using (Py.GIL())
{
var script = Py.Import("example");
var result = script.InvokeMethod("foo");
}
The script is as follows:
def foo():
return 1
It is located in a folder called example in the site-packages folder of python. The example folder also has an empty init.py file.
When I run the above C# code, I get the following error: Python.Runtime.PythonException: 'module 'example' has no attribute 'foo''
Any help would be greatly appreciated.
(untested)
https://www.educative.io/answers/how-to-call-a-python-function-from-c-sharp