IronPython/EdgeJS导入异常\uuu__

IronPython/EdgeJS导入异常\uuu__,python,node.js,ironpython,Python,Node.js,Ironpython,我正在使用EdgeJS和IronPython在我的NodeJS服务器中运行Python脚本,但是IronPython在导入模块时遇到了问题 我得到了这个错误: System.Reflection.TargetInvocationException: Exception has been thrown by the ta rget of an invocation. ---> IronPython.Runtime.Exceptions.ImportException: No mo dule

我正在使用EdgeJS和IronPython在我的NodeJS服务器中运行Python脚本,但是IronPython在导入模块时遇到了问题

我得到了这个错误:

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)
前两个文件来自,而
py.js
是调用my
search.py

Py.js

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

import metacritic 

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

lambda x: search(x)
有趣的是,如果我在同一个文件夹中创建一个名为
test.py
的临时文件,代码如下:

import metacritic

data = metacritic.mainSearch("Viva la Vida", "album");
print(data)
它起作用了。但IronPython在这一导入上遇到了障碍


有什么解决方案吗?

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

Hmm,感谢您的回复。我完全忘了我还有这个问题-我现在选择了一个完整的NodeJS解决方案…我应该关闭这个问题,还是让未来有这个问题的人来处理它?就这样吧。其他人可能也有类似的问题。
import metacritic

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