c# - IronPython 2.7.8 中的 VISBRAIN
问题描述
我正在使用 Window 7、64 位。
使用 Anaconda3。Anaconda3 在我的 D 中。
我在 Visual Studio 2017 社区中运行 C# 应用程序,试图从 Ironpython 运行 Visbrain。
我使用的 IronPython 是 IronPython 2.7.8 版。
我包括 IronPython.Modules.dll、IronPython.dll、Microsoft.Scripting.dll、Microsoft.Dynamic.dll。
我的 .net 框架是 4.0。
下面是我的代码:
// create python engine
var myPythonEngine = Python.CreateEngine();
// create search path
var searchPaths = myPythonEngine.GetSearchPaths();
searchPaths.Add(@"D:\Anaconda3\envs\myenv3604\Lib"); // using anaconda 3
//searchPaths.Add(@"D:\Python 35\Lib"); // python standard library
searchPaths.Add(@"D:\Anaconda3\envs\myenv3604\lib\site-packages"); // using anaconda 3
//searchPaths.Add(@"D:\Python 35\lib\site-packages"); // visbrain inside here
// set search path
myPythonEngine.SetSearchPaths(searchPaths);
// create scope to execute python code and get backs results from python code
var myScope = myPythonEngine.CreateScope();
// create the source
var mySource = myPythonEngine.CreateScriptSourceFromFile(@"test12345.py");
// execute the scope
mySource.Execute(myScope);
但是在我运行我的代码后,它会弹出。
IronPython.Runtime.Exceptions.ImportException: 'No module named visbrain'
尝试过的解决方案:
1) IronPython.Runtime.Exceptions.ImportException:没有名为 os 的模块
我将库添加到我的搜索路径中,但仍然没有运气
1) 的解决方案:
根据Why can't I import my C# type into IronPython?
添加
searchPaths.Add(@"D:\Python35\DLLs");
searchPaths.Add(@"D:\Python35\lib\site-packages");
===
但是我再次运行后,它会弹出这个错误:
Exception thrown: 'Microsoft.Scripting.SyntaxErrorException' in Microsoft.Dynamic.dll
An unhandled exception of type 'Microsoft.Scripting.SyntaxErrorException' occurred in Microsoft.Dynamic.dll
unexpected token 'exc_info'
堆栈跟踪如下:
Microsoft.Scripting.SyntaxErrorException
HResult=0x80131500
Message=unexpected token 'exc_info'
Source=IronPython
StackTrace:
at IronPython.Runtime.ThrowingErrorSink.Add(SourceUnit sourceUnit, String message, SourceSpan span, Int32 errorCode, Severity severity)
at IronPython.Compiler.Parser.ReportSyntaxError(Int32 start, Int32 end, String message, Int32 errorCode)
at IronPython.Compiler.Parser.ReportSyntaxError(Token t, IndexSpan span, Int32 errorCode, Boolean allowIncomplete)
at IronPython.Compiler.Parser.ParseVarArgsList(TokenKind terminator)
at IronPython.Compiler.Parser.ParseFuncDef()
at IronPython.Compiler.Parser.ParseSuite()
at IronPython.Compiler.Parser.ParseClassOrFuncBody()
at IronPython.Compiler.Parser.ParseClassDef()
at IronPython.Compiler.Parser.ParseFileWorker(Boolean makeModule, Boolean returnValue)
at IronPython.Compiler.Parser.ParseFile(Boolean makeModule, Boolean returnValue)
at IronPython.Runtime.PythonContext.ParseAndBindAst(CompilerContext context)
at IronPython.Runtime.PythonContext.CompilePythonCode(SourceUnit sourceUnit, CompilerOptions options, ErrorSink errorSink)
at IronPython.Runtime.PythonContext.CompileModule(String fileName, String moduleName, SourceUnit sourceCode, ModuleOptions options, ScriptCode& scriptCode)
at IronPython.Runtime.Importer.LoadModuleFromSource(CodeContext context, String name, String path)
at IronPython.Runtime.Importer.LoadFromDisk(CodeContext context, String name, String fullName, String str)
at IronPython.Runtime.Importer.ImportFromPathHook(CodeContext context, String name, String fullName, List path, Func`5 defaultLoader)
at IronPython.Runtime.Importer.ImportFromPath(CodeContext context, String name, String fullName, List path)
at IronPython.Runtime.Importer.ImportTopAbsolute(CodeContext context, String name)
at IronPython.Runtime.Importer.ImportModule(CodeContext context, Object globals, String modName, Boolean bottom, Int32 level)
at IronPython.Modules.Builtin.__import__(CodeContext context, String name, Object globals, Object locals, Object fromlist, Int32 level)
at Microsoft.Scripting.Interpreter.FuncCallInstruction`7.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run7[T0,T1,T2,T3,T4,T5,T6,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)
at IronPython.Runtime.Importer.ImportLightThrow(CodeContext context, String fullName, PythonTuple from, Int32 level)
at Microsoft.Scripting.Interpreter.FuncCallInstruction`4.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run1[T0,TRet](T0 arg0)
at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)
at IronPython.Runtime.PythonContext.InitializeModule(String fileName, ModuleContext moduleContext, ScriptCode scriptCode, ModuleOptions options)
at IronPython.Runtime.Importer.LoadModuleFromSource(CodeContext context, String name, String path)
at IronPython.Runtime.Importer.LoadFromDisk(CodeContext context, String name, String fullName, String str)
at IronPython.Runtime.Importer.ImportFromPathHook(CodeContext context, String name, String fullName, List path, Func`5 defaultLoader)
at IronPython.Runtime.Importer.ImportFromPath(CodeContext context, String name, String fullName, List path)
at IronPython.Runtime.Importer.ImportModule(CodeContext context, Object globals, String modName, Boolean bottom, Int32 level)
at IronPython.Modules.Builtin.__import__(CodeContext context, String name, Object globals, Object locals, Object fromlist, Int32 level)
at Microsoft.Scripting.Interpreter.FuncCallInstruction`7.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run8[T0,T1,T2,T3,T4,T5,T6,T7,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7)
at IronPython.Runtime.Importer.ImportLightThrow(CodeContext context, String fullName, PythonTuple from, Int32 level)
at Microsoft.Scripting.Interpreter.FuncCallInstruction`5.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run1[T0,TRet](T0 arg0)
at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)
at IronPython.Runtime.PythonContext.InitializeModule(String fileName, ModuleContext moduleContext, ScriptCode scriptCode, ModuleOptions options)
at IronPython.Runtime.Importer.LoadModuleFromSource(CodeContext context, String name, String path)
at IronPython.Runtime.Importer.LoadFromDisk(CodeContext context, String name, String fullName, String str)
at IronPython.Runtime.Importer.ImportFromPathHook(CodeContext context, String name, String fullName, List path, Func`5 defaultLoader)
at IronPython.Runtime.Importer.ImportFromPath(CodeContext context, String name, String fullName, List path)
at IronPython.Runtime.Importer.ImportModule(CodeContext context, Object globals, String modName, Boolean bottom, Int32 level)
at IronPython.Modules.Builtin.__import__(CodeContext context, String name, Object globals, Object locals, Object fromlist, Int32 level)
at Microsoft.Scripting.Interpreter.FuncCallInstruction`7.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run8[T0,T1,T2,T3,T4,T5,T6,T7,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7)
at System.Dynamic.UpdateDelegates.UpdateAndExecute7[T0,T1,T2,T3,T4,T5,T6,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)
at IronPython.Runtime.Importer.ImportLightThrow(CodeContext context, String fullName, PythonTuple from, Int32 level)
at Microsoft.Scripting.Interpreter.FuncCallInstruction`5.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run1[T0,TRet](T0 arg0)
at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)
at IronPython.Runtime.PythonContext.InitializeModule(String fileName, ModuleContext moduleContext, ScriptCode scriptCode, ModuleOptions options)
at IronPython.Runtime.Importer.LoadModuleFromSource(CodeContext context, String name, String path)
at IronPython.Runtime.Importer.LoadFromDisk(CodeContext context, String name, String fullName, String str)
at IronPython.Runtime.Importer.ImportFromPathHook(CodeContext context, String name, String fullName, List path, Func`5 defaultLoader)
at IronPython.Runtime.Importer.ImportFromPath(CodeContext context, String name, String fullName, List path)
at IronPython.Runtime.Importer.ImportTopAbsolute(CodeContext context, String name)
at IronPython.Runtime.Importer.ImportModule(CodeContext context, Object globals, String modName, Boolean bottom, Int32 level)
at IronPython.Modules.Builtin.__import__(CodeContext context, String name, Object globals, Object locals, Object fromlist, Int32 level)
at Microsoft.Scripting.Interpreter.FuncCallInstruction`7.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run7[T0,T1,T2,T3,T4,T5,T6,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)
at IronPython.Runtime.Importer.ImportLightThrow(CodeContext context, String fullName, PythonTuple from, Int32 level)
at Microsoft.Scripting.Interpreter.FuncCallInstruction`5.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)
at WindowsFormsAppJTTH.Form1.button1_Click(Object sender, EventArgs e) in C:\Users\JamesTan\source\repos\WindowsFormsAppJTTH\WindowsFormsAppJTTH\Form1.cs:line 170
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at WindowsFormsAppJTTH.Program.Main() in C:\Users\JamesTan\source\repos\WindowsFormsAppJTTH\WindowsFormsAppJTTH\Program.cs:line 19
想知道有没有办法解决这个问题?
解决方案
我阅读了所有文档,这就是我发现的。
根据 Visbrain ( http://visbrain.org/ ) 的文档,Visbrain 是 Python 3 包。
据 Iron Python 的开发者称,他们目前正在开发 Iron Python 2,无法支持 Python 3 包。
因此,在实施 Iron Python 3 时,这个错误可能会得到解决。
推荐阅读
- python - 如何创建一个函数来判断一个值是增加还是减少?
- python - 如何在训练 Keras 功能 API 模型时打印不同激活层的准确性?(张量流 Python)
- python - 如何从数据字典中提取值,例如 Python Panda 数据框中 CSV 文件中的值
- python - Python XGBoost GPU 版本的性能不如 CPU 版本的准确度 - 参数调优
- r - 当有多个个体时如何通过 ID 计算平均值,当 R 中的缺失值只有一个时如何计算中位数?
- flutter - 对流中的对象列表进行排序,并将排序后的列表作为流返回
- c - 计算标记联合的 malloc 大小(不过度分配)
- azure-logic-apps - 逻辑应用 - 在不同 JSON 数据源上引用和映射字段
- python - 从源窗口安装opencv
- git - git filter-branch 不删除文件