C#C
C#2y ago
13 replies
banshi

✅ Python.Net import issue

I'm trying to execute my python script from .Net using pythonnet package & i'm doing this in my wsl Ubuntu machine but when i try to import my script it throwing an error

Unhandled exception. Python.Runtime.PythonException: No module named 'myScript'




using Python.Runtime;

ExecuteScriptUsingPythonNet("myScript");
static void ExecuteScriptUsingPythonNet(string scriptName)
{
Runtime.PythonDLL = @"/usr/lib/x86_64-linux-gnu/libpython3.10.so";

PythonEngine.Initialize();
using (Py.GIL())
{
dynamic pythonScript = Py.Import(scriptName);
dynamic result = pythonScript.add_numbers(3, 5);
// dynamic result = pythonScript.getImage();

Console.WriteLine("Result: " + result);
}
PythonEngine.Shutdown();
}
Was this page helpful?