System.AccessViolationException for latest verion (3.0.0-preview2022-04-03)
See original GitHub issueEnvironment
- Pythonnet version: 3.0.0-preview2022-04-03
- Python version: 3.9.7
- Operating System: Windows 10 (version 21H2)
- .NET Runtime: 5.0
Details
-
Describe what you were trying to get done.
Run the example C# program.
-
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.
using Python.Runtime;
using System;
using System.Collections.Generic;
namespace PythonCondaEnvironment
{
internal class Program
{
static void Main(string[] args)
{
using (Py.GIL())
{
dynamic np = Py.Import("numpy");
Console.WriteLine(np.cos(np.pi * 2));
dynamic sin = np.sin;
Console.WriteLine(sin(5));
double c = (double)(np.cos(5) + sin(5));
Console.WriteLine(c);
dynamic a = np.array(new List<float> { 1, 2, 3 });
Console.WriteLine(a.dtype);
dynamic b = np.array(new List<float> { 6, 5, 4 }, dtype: np.int32);
Console.WriteLine(b.dtype);
Console.WriteLine(a * b);
Console.ReadKey();
}
}
}
}
- If there was a crash, please include the traceback here.
System.AccessViolationException
HResult=0x80004003
Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Source=<Cannot evaluate the exception source>
StackTrace:
<Cannot evaluate the exception stack trace>
Note: the above code works for last version: 3.0.0-preview2022-03-03, but for this version: 3.0.0-preview2022-04-03, it is not working any more!
Issue Analytics
- State:
- Created a year ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
AccessViolationException Class (System)
Initializes a new instance of the AccessViolationException class with a system-supplied message that describes the error.
Read more >c# - Programs randomly getting System. ...
I can confirm this problem. It occurs in a small (very trivial) WinForms program distributed with my own commercial app. It's never happened...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
it is need PythonEngine.Shutdown(); `// See https://aka.ms/new-console-template for more information global using System; using Python.Runtime; using Serilog;
static void Main() {
}`
Hello: Thanks for your reply.
I figured it out: Add PYTHONHOME in user variable, and Add PYTHONPATH to system variable. Then add: PythonEngine.Initialize(); Before this statment: using (Py.GIL()) Then run my code, it works with latest version: 3.0.0-preview2022-04-03. I think the document is not well written for this issue. By the way, I didn’t try to use Python 3.10 yet. As far as I know, there are many package not working in Python 3.10 yet, so using the latest version of Python, you may have risk not able to run many programs. But thanks for your help.