Repository navigation
Add the standard library to a .NET project
StΓ©phane Lozier edited this page Nov 6, 2026
·
9 revisions
ScriptEngine.SetSearchPaths returns sets the search paths used by the engine for loading files when a script wants to import or require another file of code.
To ship the standard library with your application, or embed it in your assembly, see Embedding the standard library.
The structure of the project
C:\
βββ Project\
β βββ Program.cs
β βββ Scripts\
β βββ utils.py
β
class Program
{
static void Main()
{
// Create the IronPython engine
ScriptEngine engine = Python.CreateEngine();
var path = engine.GetSearchPaths(); // This method returns the search paths used by the engine for loading files
path.Add(@"C:\main\Scripts"); // Add the path
engine.SetSearchPaths(path); // Sets the search path
engine.ExecuteFile(@"C:\Scripts\utils.py"); // Execute script
}
}
If the modules are distributed in different locations:
C:\
βββ Project\
βββ Library\
βββ library.py
D:\
βββ PythonLibst\
βββ utils.py
F:\
βββ Scripts\
βββ maths.py
library.py:
import utils
import maths
print(utils.sayHello())
print(maths.addition(5, 8))
utils.py
def sayHello():
return "Hello from Python"
maths.py
def addition(a, b):
return a + b
C#
ScriptEngine engine = Python.CreateEngine();
var paths = new List<string>
{
@"C:\Project\Library",
@"D:\PythonLibst",
@"F:\Scripts"
};
engine.SetSearchPaths(paths);
engine.ExecuteFile(@"C:\Project\Library\library.py");
IronPython will search for modules in this order:
- C:\Project\Library
- D:\PythonLibst
- F:\Scripts
Still looking for more? Browse the Discussions tab, where you can ask questions to the IronPython community.
π IronPython