-
Notifications
You must be signed in to change notification settings - Fork 762
Description
Environment
- Pythonnet version: 3.0.0
- Python version: 3.8
- Operating System: Windows 11
- .NET Runtime: .NET 6.0
Details
- Describe what you were trying to get done.
I am trying to call python scripts from my C# WPF Desktop Application project. In the beginning, I just wanted to test to see if I could embed simple python into the application, and then worry about calling the scripts later. This is where issues started to come up.
- What commands did you run to trigger this issue? If you can provide a
Minimal, Complete, and Verifiable example
this will help us understand the issue.
Here is the code that I am trying to run:
//string pythonPath2 = @"C:\Users\leven\AppData\Local\Programs\Python\Python38\Lib\site-packages";
string pythonPath1 = @"C:\Users\leven\AppData\Local\Programs\Python\Python38";
Runtime.PythonDLL = @"C:\Users\leven\AppData\Local\Programs\Python\Python38\python38.dll";
//string pythonDll = @"C:\Users\leven\AppData\Local\Programs\Python\Python38\python38.dll";
//Environment.SetEnvironmentVariable("PYTHONNET_PYDLL", pythonDll, EnvironmentVariableTarget.Process);
//Environment.SetEnvironmentVariable("PYTHONHOME", pythonPath1, EnvironmentVariableTarget.Process);
PythonEngine.Initialize();
using (Py.GIL()) {
dynamic os = Py.Import("os");
dynamic dir = os.listdir();
Debug.WriteLine(dir);
foreach (var d in dir) {
Debug.WriteLine(d);
}
}
The commented out code was just me trying different solutions from other answers online. Those did not work either. I cloned the master branch and ran the pip command to generate the Python.Runtime.dll. I then added that dll as a reference to my project. I also tried just simply pip install pythonnet
and add the reference to Python.Runtime.dll located in my site-packages. That also didn't work. Finally, I tried adding the pythonnet nuget package, which also didn't end with success.
- If there was a crash, please include the traceback here.
Here's the error I am getting. It's happening at the PythonEngine.Initialize(); line.
Exception thrown: 'System.MissingMethodException' in Python.Runtime.dll
Failed to load symbol PyBuffer_SizeFromFormat.
I appreciate the help in advance, and let me know if any more information is needed!