IronPython.Runtime.Exceptions.ImportException: "No module named
ManfreddEE opened this issue · comments
Calling the specified script via C# is working,
but the python-command 'from x.y import *' fails.
With this command, there should be imported a user defined python-class or other defined functions in subfolders.
ActualFolder
->script1.py
->script2.py
->....
->Subfolder
->scriptSub1.py
->scriptSub2.py
->....
e.g. command in script1.py
from Subfolder.scriptSub1 import *;
Everything works fine, when i call the script via the 'cmd.exe' (all subscripts are imported in a working way).
It's also working fine, when i use a 'C#-Process'
Using IronPython (V2.7.11) in the following way:
// 1)
var engine = Python.CreateEngine();
// 2) provide scriptPath and arguments
var scriptPath = @"Path\to\file\fileName.py";
string dir = Path.GetDirectoryName(scriptPath);
// 3)
ICollection<string> paths = engine.GetSearchPaths();
if (!String.IsNullOrWhiteSpace(dir))
paths.Add(dir);
else
paths.Add(Environment.CurrentDirectory);
engine.SetSearchPaths(paths);
var source = engine.CreateScriptSourceFromFile(scriptPath);
// 4) Execute scriptPath
var scope = engine.CreateScope();
source.Execute(scope);
In "source.Execute(scope)" following exception: IronPython.Runtime.Exceptions.ImportException: "No module named Subfolder.scriptSub1" is thrown.
Thanks for suggested solutions
Does your Subfolder include an __init__.py
file? This file is required to make it a package with Python 2.7.
Does your Subfolder include an
__init__.py
file? This file is required to make it a package with Python 2.7.
Thank you very much for the information, 'slozier'.