IronPython/EdgeJS Import Exception __future__

I'm using EdgeJS with IronPython to run a Python script inside my NodeJS server, but IronPython is having trouble importing a module.

I'm getting this error:

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)

In my directories I have:

-src
  |
  - metacritic.py
  - BeautifulSoup.py
  - py.js
  - search.py

The first two files come from the Metacritic scraper, and py.js is the NodeJS file that calls 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)

The interesting thing is, if I create a temporary file called test.py in the same folder, with the code:

import metacritic

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

It works. But IronPython is stumbling on this import.

Any solutions?

It looks like IronPython can't find its standard library. You might have to tweak py.js and add a call to ScriptEngine.SetSearchPaths to include the standard library location.