pythonnet ( https://github.com/renshawbay/pythonnetにある python3 互換バージョン)を使用して、C# から組み込みの python インタープリターを使用しようとしています。
私のインタープリターは 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 からオブジェクトを取得しようとするたびに、コードが失敗します。
私は何を間違っていますか?