gpt4 book ai didi

C#:使用 Python.Runtime 未找到

转载 作者:行者123 更新时间:2023-12-01 01:47:24 25 4
gpt4 key购买 nike

我尝试使用 Python for .NET 嵌入 python 脚本。在C#程序中,我尝试导入该类

using Python.RunTime;

但找不到。我无法找出其中的原因。我已经在我的 python 解释器中安装了 pythonnet。

我只是想通过以下代码来测试它:

using (Py.GIL)
{
dynamic np = Py.Import("numpy");
MessageBox.Show(np.cos(np.pi * 2));
}

* 更新 *

我在VS项目中添加了引用Python.Runtime.dll。当执行时,它得到了System.BadImageFormatException。我不知道为什么会这样。

最佳答案

希望这个答案可以帮助其他遇到类似问题的人。

  1. 将 dll 添加为 VS 中的引用。它应该位于“C:\Python27\Lib\site-packages\Python.Runtime.dll”之类的位置。如果您已经通过 pip 安装了 pythonnet。

  2. System.BadImageFormatException 是由于我将项目设置为任何平台的问题,但 python 解释器是 64 位。需要更改目标平台以匹配解释器。

关于C#:使用 Python.Runtime 未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51121456/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com