我正在尝试使用 pythonnet 使用来自 C# 的嵌入式 python 解释器(在https://github.com/renshawbay/pythonnet找到的 python3 兼容版本)
我的解释器位于 D:\src\scratch\TestPythonNet\TestPythonNet\PythonRuntime 并具有来自 python 发行版的“Lib”和“Libs”文件夹。
我已经使用以下代码进行了测试:
<!-- language: c# -->
PythonEngine.PythonHome = @"D:\src\scratch\TestPythonNet\TestPythonNet\PythonRuntime";
PythonEngine.ProgramName = "PythonRuntime";
PythonEngine.Initialize();
using (Py.GIL())
{
PythonEngine.RunSimpleString("print(1)");
}
但是,它不起作用。我得到一个“SystemError:PyEvalCodeEx:NULL globals”。每次我尝试从 python 获取对象时,代码都会失败。
我究竟做错了什么?