PythonEngine.Initialize() 失败,没有任何错误信息

PythonEngine.Initialize() fails without any error message

我正在尝试将 Python 嵌入到 C# 应用程序中,但我似乎无法让它工作。 我的代码是

using System;
using Python.Runtime;

namespace NLP.Python
{
   public class PythonRumtime
   {
       public PythonRuntime()
    {
       //Location of python installation
       PythonEngine.PythonHome = "C:\Python27";
       PythonEngine.Initialize();
     }
    }
 }

当我尝试创建此 class 的实例时,代码在调用 PythonEngine.Initialize() 时失败且没有任何错误 我已经添加了对随 pythonnet 安装的 dll 文件 Python.Runtime 的引用。

我不知道还能做什么。

我在一台 Windows 64 位机器上通过 pip 安装了 pythonnet-2.1.0,32 位机器安装了 Python 2.7.11.

EDIT 错误似乎发生在调用 Python.Runtime.dll 中的 Py_Initialize() 时。 根据https://docs.python.org/2/c-api/init.html"There is no return value; it is a fatal error if the initialization fails."

这是 python.org windows python 2.7.11 32 位官方 windows 安装程序中的错误:

https://bugs.python.org/issue25824

试试 Anaconda,也许是 WinPython 或 python 2.7.10.