private void OsModuleWorkaround() { IPythonEngine engine = GetCurrentCore().PythonEngine; var progFilesX68 = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86); string pythonLibDir = Path.Combine(progFilesX68, "ironpython 2.7", "lib"); if (!Directory.Exists(pythonLibDir)) { var activeForm = Form.ActiveForm ?? (Form)this.GetCurrentCore().Tag; pythonLibDir = (string)activeForm.Invoke(new Func <string>(this.GetPythonLibDir)); if (String.IsNullOrEmpty(pythonLibDir)) { throw new FatalActionException("Could not find Python Lib folder", this); } } engine.ImportModule("sys"); engine.Execute(string.Format("sys.path.append('{0}')\n", pythonLibDir)); engine.ImportModule("os"); }
protected override void DoAction() { IPythonEngine engine = GetCurrentCore().PythonEngine; try { foreach (var module in Modules.Split(',').Select(s => s.Trim())) { if (module == "os") { //workaround for os module not included in embedded ironpython this.OsModuleWorkaround(); } else { engine.ImportModule(module); } } } catch (PythonException e) { throw new ActionException(e, this); } }