首页 > 解决方案 > Unity IronPython ImportException:没有名为 __future__ 的模块

问题描述

我一直在使用 IronPython 作为我的 Unity 项目的一部分。这是我的代码的 IronPython 部分:

var engine = Python.CreateEngine();
ICollection<string> searchPaths = engine.GetSearchPaths();
searchPaths.Add(@"C:\Tamir\final_project\Final_Project\Assets\Plugins\sunfish-master");
searchPaths.Add(@"C:\Tamir\final_project\Final_Project\Assets\Plugins\Lib");
dynamic py = engine.ExecuteFile(@"C:\Tamir\final_project\Final_Project\Assets\Plugins\sunfish-master\sunfish.py");

但我不断收到以下错误:

ImportException: No module named __future__
Microsoft.Scripting.Runtime.LightExceptions.ThrowException (Microsoft.Scripting.Runtime.LightExceptions+LightException lightEx) (at <6a70babe64d34e1b9136298538676a61>:0)
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)
GameManager.Start () (at Assets/Scripts/GameManager.cs:83)

错误点在这一行:engine.ExecuteFile(@"C:\Tamir\final_project\Final_Project\Assets\Plugins\sunfish-master\sunfish.py");

我检查过,C:\Tamir\final_project\Final_Project\Assets\Plugins\Lib 中有一个 __ future __.py 文件

可能是什么问题呢?

标签: pythonc#unity3dironpython

解决方案


转到cmd,运行命令,pip install future或者python -m pip install future它应该可以工作


推荐阅读