1

I have a C# application that uses IronPython to run Python scripts. I have added the references for IronPython successfully and can run simple Python scripts.

The problem I have is running Python scripts that import modules. I know I have to change the search paths but am having trouble doing it successfully.

I have a separate Anaconda distribution of Python with modules in there. How can change the search path of IronPython so I can get access to these modules?

It is a Windows10 system.

  • What did you try? What happens? What resources did you look at? Are you sure that the required modules are pure python without native components? Do you also add iron python's own standard lib? – Simon Opelt May 22 '16 at 19:27

1 Answers1

0

Take a look here general dlr implementation - adding search path (simplic-dlr).

This lines are important:

/// <summary>
/// Add additional search path to look for modules/packages in the filesystem
/// </summary>
/// <param name="path">Path to the modules</param>
public void AddSearchPath(string path)
{
    if (string.IsNullOrWhiteSpace(path))
    {
        throw new ArgumentException("Invalid path information passed to AddSearchPath. Path must not be null or white space");
    }

    var paths = scriptEngine.GetSearchPaths();
    paths.Add(path);
    scriptEngine.SetSearchPaths(paths);
}

Just add everything to your ScriptEngine instance.

BendEg
  • 20,098
  • 17
  • 57
  • 131