我现在正在使用Iron Python在C#中运行基于Python的dll
我的C代码中有一行:
public void Runpython(string name, string id)
{
var engine = Python.CreateEngine();
//Get Dll
var path = Environment.CurrentDirectory;
var fullPath = @$"{path}\PythonService.dll";
engine.Runtime.LoadAssembly(Assembly.LoadFile(fullPath));
//Get pythonservice.py file
var scope = engine.Runtime.ImportModule("pythonservice");
//Get PythonService class
var pythonService = scope.GetVariable("PythonService");
//Run function
var pyService = engine.Operations.CreateInstance(pythonService);
var result = pyService.save(name, id);
Console.WriteLine(result);
}
异常发生在这一行:var scope = engine.Runtime.ImportModule("pythonservice");
当它试图获取我包装在dll中的pythonservice.py
文件时
我能知道是什么原因造成的吗
我使用的是Iron Python 2.7.11,我的C#类库和控制台应用程序都是.NET Core 3.1
多谢各位
你可以不用IronPython做同样的工作
在“C:\Program Files\Python39\python.exe”或任何python环境中安装库
试试这个:
用法:
并阅读python中的参数
Python代码:
要将数据返回到c#代码,您应该使用以下命令:
相关问题 更多 >
编程相关推荐