diff --git a/code/src/Form1.cs b/code/src/Form1.cs index 5c5abbd..9e71010 100644 --- a/code/src/Form1.cs +++ b/code/src/Form1.cs @@ -69,6 +69,17 @@ namespace FileWatcher private Form1() { pyEngine = Python.CreateEngine(); + + // Adding these search paths, besides Lib, fixed IronPython import exceptions. Code may run a little faster now. + var paths = pyEngine.GetSearchPaths(); + paths.Clear(); + paths.Add(FileGroupTab.GetPythonDir()); + paths.Add(Path.Combine(FileGroupTab.GetPythonDir(), "DLLs")); + paths.Add(Path.Combine(FileGroupTab.GetPythonDir(), "Lib")); + paths.Add(Path.Combine(FileGroupTab.GetPythonDir(), "Lib", "site-packages")); + paths.Add(Path.GetDirectoryName(GetType().Assembly.Location)); + pyEngine.SetSearchPaths(paths); + pyEngine.Runtime.LoadAssembly(Assembly.GetAssembly(typeof(FileWatcher.Form1))); pyScope = pyEngine.CreateScope(); @@ -81,19 +92,32 @@ namespace FileWatcher m_ErrorStream.StringWritten += new EventHandler>(script_ErrorStringWritten); pyEngine.Runtime.IO.SetErrorOutput(m_MemoryStream, m_ErrorStream); - string pythonDir = FileGroupTab.GetPythonDir(); + /*string pythonDir = FileGroupTab.GetPythonDir(); if (pythonDir != null) { string pythonLibs = Path.Combine(pythonDir, "Lib"); if (Directory.Exists(pythonLibs)) { - string import = "import sys" + Environment.NewLine + "sys.path.append('" + pythonLibs + "')" + Environment.NewLine; + //string import = "import sys" + Environment.NewLine + "sys.path.append('" + pythonLibs + "')" + Environment.NewLine; + //string import = "import clr" + Environment.NewLine; + + //import += "clr.AddReference('StdLib')" + Environment.NewLine; + + import += "clr.AddReference('IronPython')" + Environment.NewLine; + import += "clr.AddReference('IronPython.Modules')" + Environment.NewLine; + import += "clr.AddReference('Microsoft.Scripting.Metadata')" + Environment.NewLine; + import += "clr.AddReference('Microsoft.Scripting')" + Environment.NewLine; + import += "clr.AddReference('Microsoft.Dynamic')" + Environment.NewLine; + import += "clr.AddReference('mscorlib')" + Environment.NewLine; + import += "clr.AddReference('System')" + Environment.NewLine; + import += "clr.AddReference('System.Data')" + Environment.NewLine; + ScriptSource source = pyEngine.CreateScriptSourceFromString(import, SourceCodeKind.AutoDetect); object result = source.Execute(pyScope); } - } + }*/ InitializeComponent();