Issue
I try to execute a function on python from a unity C# script and I'm using the package "IronPython", but on my python file I'm using - matplotlib.pyplot and I get from my unity editor the next error:
ImportException: No module named matplotlib.pyplot
Microsoft.Scripting.Runtime.LightExceptions.CheckAndThrow (System.Object value) (at <6a70babe64d34e1b9136298538676a61>:0)
Microsoft.Scripting.Interpreter.FuncCallInstruction`2[T0,TRet].Run (Microsoft.Scripting.Interpreter.InterpretedFrame frame) (at <6a70babe64d34e1b9136298538676a61>:0)
Microsoft.Scripting.Interpreter.Interpreter.Run (Microsoft.Scripting.Interpreter.InterpretedFrame frame) (at <6a70babe64d34e1b9136298538676a61>:0)
Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet] (T0 arg0, T1 arg1) (at <6a70babe64d34e1b9136298538676a61>:0)
IronPython.Compiler.PythonScriptCode.RunWorker (IronPython.Runtime.CodeContext ctx) (at <4e01c3e2a6d647c6b8da08b7a074e47b>:0)
IronPython.Compiler.PythonScriptCode.Run (Microsoft.Scripting.Runtime.Scope scope) (at <4e01c3e2a6d647c6b8da08b7a074e47b>:0)
IronPython.Compiler.RuntimeScriptCode.InvokeTarget (Microsoft.Scripting.Runtime.Scope scope) (at <4e01c3e2a6d647c6b8da08b7a074e47b>:0)
IronPython.Compiler.RuntimeScriptCode.Run (Microsoft.Scripting.Runtime.Scope scope) (at <4e01c3e2a6d647c6b8da08b7a074e47b>:0)
Microsoft.Scripting.SourceUnit.Execute (Microsoft.Scripting.Runtime.Scope scope, Microsoft.Scripting.ErrorSink errorSink) (at <ab6bb51465f44fb2b67d2937d9bd64f2>:0)
Microsoft.Scripting.SourceUnit.Execute (Microsoft.Scripting.Runtime.Scope scope) (at <ab6bb51465f44fb2b67d2937d9bd64f2>:0)
Microsoft.Scripting.Hosting.ScriptSource.Execute (Microsoft.Scripting.Hosting.ScriptScope scope) (at <ab6bb51465f44fb2b67d2937d9bd64f2>:0)
(wrapper remoting-invoke-with-check) Microsoft.Scripting.Hosting.ScriptSource.Execute(Microsoft.Scripting.Hosting.ScriptScope)
Microsoft.Scripting.Hosting.ScriptEngine.ExecuteFile (System.String path, Microsoft.Scripting.Hosting.ScriptScope scope) (at <ab6bb51465f44fb2b67d2937d9bd64f2>:0)
Microsoft.Scripting.Hosting.ScriptEngine.ExecuteFile (System.String path) (at <ab6bb51465f44fb2b67d2937d9bd64f2>:0)
(wrapper remoting-invoke-with-check) Microsoft.Scripting.Hosting.ScriptEngine.ExecuteFile(string)
PythonManager.SendPythonRequest (System.Collections.Generic.List`1[T] wind1, System.Collections.Generic.List`1[T] wind2, System.Collections.Generic.List`1[T] wind3, System.Collections.Generic.List`1[T] wind4, System.Collections.Generic.List`1[T] map, WindVector[,] windObject) (at Assets/Scripts/PythonManager.cs:23)
GridManager.Start () (at Assets/Scripts/GridManager.cs:44)
this is my C# script:
var engine = Python.CreateEngine();
ICollection<string> searchPaths = engine.GetSearchPaths();
//Path to the folder of greeter.py
searchPaths.Add(Application.dataPath);
//Path to the Python standard library
searchPaths.Add(Application.dataPath + @"\Plugins\Lib\");
engine.SetSearchPaths(searchPaths);
dynamic py = engine.ExecuteFile(Application.dataPath + @"\greeter.py");
dynamic TestScript = py.TestClass(wind1, wind2, wind3, wind4, map);
List<List<float>> ironList = py.generate_predictions(wind1, wind2, wind3, wind4, 315, 10, 10, windObject, true);
Debug.LogWarning(ironList);
Do someone know how do I install this matplotlib.pyplot on my C# project with IronPython? I saw that on 2012 it's was imposible but maybe today there is a way.. if there is an alternate way to call a metode with parameter from C# to python with the module matplotlib.pyplot I will be happy to know, thank you.
Solution
After a long search I discover that IronPython do not support numpy or matplotlib. So I use the Nuget package to copy my script from python to C# - it's long but working.
this is a link for the nuget package: https://github.com/GlitchEnzo/NuGetForUnity
after install this package go to Unity → NuGet → Manage NuGet Packages search for Numpy or matplotlib package and now you can use the python's module.
Answered By - noam
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.