Re: Ironpython 2.7.9 ImportException: 'No Module Named errno' when importing another module in .NET application

Alex Earl

Also, are you adding the normal C Python site-packages to your path? You should definitely not do that, there are incompatibilities with the normal C Python stdlib. This is why we have an IronPython.StdLib package with modifications.

On Wed, Nov 28, 2018 at 2:35 PM Stéphane Lozier <stephane.lozier@...> wrote:
Sounds like IronPython.Modules isn't loaded. errno is a builtin module (in IronPython.Modules) so that is the error you would get if you tried to import os without it. Did you check that it gets copied to your bin folder?

On Sun, Nov 25, 2018 at 2:48 PM micoo via Groups.Io <> wrote:
I originally asked this on SO and it got nothing, so hopefully this is a more direct way of getting some help.

I am attempting to run a simple python script within my .net application using IronPython. I have installed the nuget package into the project (I have NOT installed the ironpython cli on my machine) and have authored this code to handle setting paths, reading output, and setting input.
    this.engine = Python.CreateEngine();
    this.scope = this.engine.CreateScope();
    this.streamOut = new MemoryStream();
    this.streamErr = new MemoryStream();
    this.engine.Runtime.IO.SetOutput(this.streamOut, Encoding.Default);
    this.engine.Runtime.IO.SetErrorOutput(this.streamErr, Encoding.Default);
    // this is a locally set environment variable 
    string pythonRootPath = Environment.GetEnvironmentVariable("PythonPath");
    ICollection<string> searchPaths = engine.GetSearchPaths();
    this.engine.Execute(@"import jinja2");
Executing the script results in the following exception
    IronPython.Runtime.Exceptions.ImportException: 'No module named errno'
My C# project has references to the following relevant (to IronPython) assemblies:
 - IronPython (v2.7.9)
 - IronPython.Modules
 - IronPython.SQLite
 - IronPython.Wpf
 - Microsoft.Dynamic
 - Microsoft.Scripting
 - Microsoft.Scripting.Metadata
My paths appear to be well enough set for my purposes as it's not the import of jinja2 itself that causes the error and I am able to import some standard library modules. However, I've seen that the 'os' package fails to import for the same reason as jinja2. I also cannot import errno directly as expected, but I can import it directly if I run it via the python 2.7 cli so the package is installed.
I'm very much out of ideas here if anyone has any suggestions.

Join to automatically receive all group messages.