I am trying to run some Python scripts in my UWP project with pythonnet. After setting Runtime.PythonDLL
equal to python38.dll path, PythonEngine.Initialize();
throws a 'System.DllNotFoundException'
. Specifically, Win32Exception: Access Denied
. Here's the code that I am trying to run:
private void searchCatButton_Click(object sender, RoutedEventArgs e) {
Runtime.PythonDLL = @"**path to Python38**\python38.dll";
PythonEngine.Initialize();
using(Py.GIL()) {
dynamic os = Py.Import("os");
dynamic dir = os.listdir();
Console.WriteLine(dir);
foreach (var d in dir) {
Console.WriteLine(d);
}
}
}
The python38.dll file is located in AppData folder. Not sure if I am supposed to give some kind of permissions to the project or if I am missing something much bigger.
Thanks for the help in advance, and let me know if there's information missing from the post!
Edit:
I tried to run as administrator... same error. I created a whole new project and can't seem to get it to work there either. I'm completely out of ideas.
Edit 2.0:
I was able to get rid of this error by installing the LostTech.Python.Runtime nuget package. Someone recommended from a different post. But now I'm getting a different error... PythonEngine.Initialize();
now outputs the following error message: Exception thrown: 'System.TypeInitializationException' in Python.Runtime.dll The type initializer for 'Delegates' threw an exception.
. Not sure if my previous error is fixed by installing the nuget package, but now I have this error I cannot seem to fix.