Ironpython Standard Library Modules

As we know, Ironpython Standard Library Path needs to be added to sys.path
so that python can find modules like os, random etc.

import sys
sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\Lib)
import os   
# importing os without appending to path raises Import Error

But I recently found out something that has intrigued me: re and math modules can be imported without modifying the path which is empty by default

# top of script
import re
import random

Does anyone know how that’s possible? Are there other modules that can also be imported without being on a PATH location? Or perhaps point me to me the portion of the source code where that’s defined?

I looked through this but did not see anything that answers these questions.

ps: @Andreas_Dieckmann @Dimitar_Venkov @Konrad_K_Sobon :slight_smile:

1 Like

That’s because some modules are implemented using native c# libs and reside in the IronPythonModules.dll, which is loaded automatically at startup. The rest of the ipy modules are implemented as python code (and reside in the Lib folder) and are translated to the CLR’s intermediate language every time you run the script:


Ha. That makes perfect sense.
Thank you!