当我使用C#运行python代码时,出现此错误
Microsoft.Dynamic.dll中发生了类型为'IronPython.Runtime.Exceptions.ImportException'的未处理异常
其他信息:没有名为_imp的模块
如何解决此错误,请帮助我
这是我的代码
Process process = new Process(); //to make a process call
ScriptEngine engine = Python.CreateEngine(); //For Engine to initiate the script
List<string> pathes = engine.GetSearchPaths().ToList();
pathes.AddRange(new[]
{
@"C:\Program Files\Python 3.5\python.exe",@"E:\Work\MaskGenerate\MaskGenerate\bin\Debug",
@"E:\Work\MaskGenerate\MaskGenerate\bin\Debug\image.py",@"C:\Program Files\Python 3.5\python35.zip",
@"C:\Program Files\Python 3.5\DLLs",@"C:\Program Files\Python 3.5\lib",@"C:\Program Files\Python 3.5",
@"C:\Program Files\Python 3.5\lib\site-packages",@"E:\Work\MaskGenerate\MaskGenerate\Lib"
});
engine.SetSearchPaths(pathes);
var b = engine.GetBuiltinModule();
var a = engine.GetClrModule();
//dynamic logging = engine.ImportModule("cv2");
//engine.ExecuteFile(@"./image.py");//Path of my .py file that I would like to see running in console after running my .cs file from VS.//process.StandardInput.Flush();
var source = engine.CreateScriptSourceFromFile(@"E:\Work\MaskGenerate\MaskGenerate\bin\Debug\image.py");
var scope = engine.CreateScope();
CompiledCode compiled = source.Compile();
compiled.Execute(scope);
var classCalculator = scope.GetVariable("image");
//initializing class
var calculatorInstance = engine.Operations.CreateInstance(classCalculator);
pictureBox1.Image = calculatorInstance.getimage();