首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IronPython/EdgeJS导入异常__future__

IronPython/EdgeJS导入异常__future__
EN

Stack Overflow用户
提问于 2014-08-01 04:54:08
回答 1查看 654关注 0票数 0

我使用EdgeJS和IronPython在IronPython服务器中运行NodeJS脚本,但是IronPython在导入模块时遇到了困难。

我得到了一个错误:

代码语言:javascript
复制
System.Reflection.TargetInvocationException: Exception has been thrown by the ta
rget of an invocation. ---> IronPython.Runtime.Exceptions.ImportException: No mo
dule named __future__
   at Microsoft.Scripting.Runtime.LightExceptions.CheckAndThrow(Object value)
   at Microsoft.Scripting.Interpreter.FuncCallInstruction`2.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.Compiler.RuntimeScriptCode.Run(Scope scope)
   at IronPython.Runtime.PythonContext.InitializeModule(String fileName, ModuleC
ontext moduleContext, ScriptCode scriptCode, ModuleOptions options)
   at IronPython.Runtime.PythonContext.CompileModule(String fileName, String mod
uleName, SourceUnit sourceCode, ModuleOptions options, ScriptCode& scriptCode)
   at IronPython.Runtime.Importer.LoadModuleFromSource(CodeContext context, Stri
ng 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 nam
e, String fullName, List path)
   at IronPython.Runtime.Importer.ImportTopAbsolute(CodeContext context, String
name)
   at IronPython.Runtime.Importer.ImportModule(CodeContext context, Object globa
ls, String modName, Boolean bottom, Int32 level)
   at IronPython.Modules.Builtin.__import__(CodeContext context, String name, Ob
ject 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 f
ullName, PythonTuple from, Int32 level)
   at IronPython.Runtime.Operations.PythonOps.ImportWithNames(CodeContext contex
t, String fullName, String[] names, 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.Compiler.RuntimeScriptCode.Run(Scope scope)
   at IronPython.Runtime.PythonContext.InitializeModule(String fileName, ModuleC
ontext moduleContext, ScriptCode scriptCode, ModuleOptions options)
   at IronPython.Runtime.PythonContext.CompileModule(String fileName, String mod
uleName, SourceUnit sourceCode, ModuleOptions options, ScriptCode& scriptCode)
   at IronPython.Runtime.Importer.LoadModuleFromSource(CodeContext context, Stri
ng 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 nam
e, String fullName, List path)
   at IronPython.Runtime.Importer.ImportTopAbsolute(CodeContext context, String
name)
   at IronPython.Runtime.Importer.ImportModule(CodeContext context, Object globa
ls, String modName, Boolean bottom, Int32 level)
   at IronPython.Modules.Builtin.__import__(CodeContext context, String name, Ob
ject 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 System.Dynamic.UpdateDelegates.UpdateAndExecute6[T0,T1,T2,T3,T4,T5,TRet](C
allSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
   at IronPython.Runtime.Importer.ImportLightThrow(CodeContext context, String f
ullName, PythonTuple from, Int32 level)
   at IronPython.Runtime.Operations.PythonOps.ImportTop(CodeContext context, Str
ing fullName, 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.Compiler.RuntimeScriptCode.Run()
   at Microsoft.Scripting.Hosting.ScriptSource.Execute()
   at EdgeCompiler.CompileFunc(IDictionary`2 parameters)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments,
 Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Objec
t[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invoke
Attr, Binder binder, Object[] parameters, CultureInfo culture)
   at ClrFunc.Initialize(Handle<v8::Value>* , Arguments* args)

在我的目录中:

代码语言:javascript
复制
-src
  |
  - metacritic.py
  - BeautifulSoup.py
  - py.js
  - search.py

前两个文件来自铁素体刮板机py.js是调用py.js search.py的NodeJS文件

Py.js

代码语言:javascript
复制
var edge = require('edge');

var search = edge.func('py', 'search.py');

search('Viva la Vida', function (error, result) {
    if (error) throw error;
    console.log(result);
});

Search.py

代码语言:javascript
复制
import metacritic 

def search(obj):
    return metacritic.mainSearch("Viva la Vida", "album");

lambda x: search(x)

有趣的是,如果我在同一个文件夹中创建一个名为test.py的临时文件,并使用以下代码:

代码语言:javascript
复制
import metacritic

data = metacritic.mainSearch("Viva la Vida", "album");
print(data)

它起作用了。但IronPython在这一进口上遇到了绊脚石。

有什么解决办法吗?

EN

回答 1

Stack Overflow用户

发布于 2014-08-05 07:59:50

看起来IronPython找不到它的标准库。您可能必须调整py.js并添加对ScriptEngine.SetSearchPaths的调用,以包括标准库位置。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25073067

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档