python - 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 文件
可能是什么问题呢?
解决方案
转到cmd,运行命令,pip install future
或者python -m pip install future
它应该可以工作
推荐阅读
- javascript - 将 DOM 操作与轮播中的样式更改同步的问题
- node.js - 我怎样才能等到加载掩码在量角器中消失?
- python - 使用功能级别标记来确定应该在 after_scenario 中使用行为清理哪个场景
- python - 如何制作这样的循环 3 维?
- python - 在 Python matplotlib 中添加图例
- html - 仅在 Web 动画期间才考虑 60FPS 吗?
- fortran - 在数组 fortran 中查找非零元素的索引
- c++ - 线程彼此减慢
- javascript - 在 .env 文件中读取导出的变量 nodejs
- css - 阻止 @import CSS 的页面渲染