It is possible. You just need to add search paths to ScriptEngine object like this:
var paths = engine.GetSearchPaths();
paths.Add(yourLibsPath); // add directory to search
or
engine.SetSearchPaths(paths);
Then you could use any module in directories, which you add:
import pyFileName # without extension .py
Update
OK. If you want to use embedded resource strings like module, you may use this code:
var scope = engine.CreateScope(); // Create ScriptScope to use it like a module
engine.Execute("import clr\n" +
"clr.AddReference(\"System.Windows.Forms\")\n" +
"import System.Windows.Forms\n" +
"def Hello():\n" +
"\tSystem.Windows.Forms.MessageBox.Show(\"Hello World!\")", scope); // Execute code from string in scope.
Now you have a ScriptScope object (scope in code) containing all executed functions. And you may insert them into another scope like this:
foreach (var keyValuePair in scope.GetItems())
{
if(keyValuePair.Value != null)
anotherScope.SetVariable(keyValuePair.Key, keyValuePair.Value);
}
Or you can execute your scripts right in this ScriptScope:
dynamic executed = engine.ExecuteFile("Filename.py", scope);
executed.SomeFuncInFilename();
And in this script you may use all functions without import:
def SomeFuncInFilename():
Hello() # uses function from your scope