IronPython ImportException: No module named logging

11,761

It's not enough to add the assemblies to your C# application. logging is written in python, and it's part of the standard library. You'll have to add the standard library to IRONPYTHONPATH as well. You can do it like this:

var engine = Python.CreateEngine();
var paths = engine.GetSearchPaths();
paths.Add(@"C:\Path\to\your\standard\library");
engine.SetSearchPaths(paths);

If you need the standard library you would probably need to ship it with your application. My suggestion is to zip it and then add the zip file to the paths.

Share:
11,761
chtenb
Author by

chtenb

Updated on June 04, 2022

Comments

  • chtenb
    chtenb almost 2 years

    I got ironpython working fine on mono, but it doesn't import the logging module. Executing this code:

    ScriptEngine engine = Python.CreateEngine();
    dynamic logging = engine.ImportModule("logging");
    

    yields the following error:

    IronPython.Runtime.Exceptions.ImportException: No module named logging
    

    The IronPython assemblies I have included are up-to-date: IronPython.Modules.dll, Microsoft.Dynamic.dll, Microsoft.Scripting.dll, Microsoft.Scripting.Metadata.dll.

    How can I make use of the logging module within Ironpython?

  • chtenb
    chtenb over 10 years
    Thanks for the answer. Is there a generic, platform independent way to add the standard library to the path? I suppose that hardcoding this path will only work on my pc
  • Viktor Kerkez
    Viktor Kerkez over 10 years
    @Chiel92 Yes, don't hardcode it. I updated the question. If you ship the standard library with your app, then could infer the (relative or absolute) path to it.
  • chtenb
    chtenb over 10 years
    Okay, that's kind of a lot of space ;) Like 150 MB. I would like to find a way to still use the system-wide python lib
  • Viktor Kerkez
    Viktor Kerkez over 10 years
    @Chiel92 They are not 100% compatible. IronPython made some changes to the standard library it ships with the binaries.
  • chtenb
    chtenb over 10 years
    Good to know. So shipping is really the only option? Or is there a way to have a system-wide ironpython installation? (Its getting more complex now)
  • Viktor Kerkez
    Viktor Kerkez over 10 years
    @Chiel92 If you have a system wide IronPython installation then you can use the standard library from the installation. Just take care that the version you use the dlls from and the version installed match. But then, how would you know where it's installed :) Especially if you want to be cross-platform... :-/
  • chtenb
    chtenb over 10 years
    Well that sucks :) I think shipping ironpython is indeed the way to go for now
  • Sven
    Sven over 8 years
    As i understand it you can zip whatever parts you need.
  • user3450049
    user3450049 about 6 years
    when I include logging by including the logging folder in my path, I then get the error: unexpected token 'exc_info'. Can anyone please offer help with that error?