Python 对于 .NET:System.BadImageFormatException 嵌入时

Python for .NET: System.BadImageFormatException when embedding

我正在尝试将 Python 嵌入到我的 .NET 应用程序中。

我在 Windows 10 上使用 Python 3.6.1 64 位,我已经使用 pip 从 PyPi 安装了 pythonnet 2.3.0。

我从 C:\Program Files\Python36\Lib\site-packages 引用了 Python.Runtime.dll 并且 PathPYTHONHOME 环境变量都指向 C:\Program Files\Python36\

当我在 Python 中使用 .NET 时一切正常。

import clr
from System.Drawing import Point
p = Point(5, 5)
print(p)

按预期打印 {X=5,Y=5}

但是当我从 .NET 调用 Python 时,我得到 System.BadImageFormatException。例如,调用 Python.Runtime.PythonEngine.Initialize(); 时:

System.BadImageFormatException: 'Could not load file or assembly 'Python.Runtime, Version=2.3.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.'

有什么想法吗?

提前致谢。

,我只是从 32 位 .NET 进程调用。