Accessing the Standard Library from IronPython

Must Read

Learn Scientific Advertising and Ad Copywriting

Claude Hopkins’ Scientific Advertising provides a solid backdrop for understanding the importance of advertising testing and refinement. But it...

Sound Recorder (Saving Audio Files & Playing Sound Backward)

Sound Recorder enables you to record, manage, and play audio clips. It is named after the Sound Recorder program...

3 Things Every Student Should Know About Student Loan Consolidation

Student loans differ from other types of loans in that they usually offer a greater amount of leeway in...

Eliminate Debts Cheaply Through Secured Debt Consolidation Loans

If you think it is high time that you pay off all those debts, otherwise you may be inviting...

What Is Home Equity Loan

In its simplest definition, home equity loan means using your house equity as collateral in order to borrow money....

Bare-Tubed Strobe

A bare-tubed strobe is about the closest one can get to a true “point” light source. Without any modifiers,...

Before you can use the Python Standard Library to create applications, you must provide a means for IronPython to find the Standard Library so it can import modules. You have three options for performing this task.

  • Create an environment variable named IRONPYTHONPATH and provide the path to the Standard Library through it.
  • Manually add the path to the import search path (discussed later in this section). The advantage of this method is that the import requirements move with the application. However, if the user has their copy of the Standard Library in a different location (or doesn’t have the Standard Library installed at all), the change can break your application.
  • Add the path to, which is located in the Program FilesIronPython 2.6Lib directory of your machine. The interpreter loads this file every time it starts, so you can be sure that everyone using the IronPython interpreter on your machine will have the required access. As with the IRONPYTHONPATH environment variable, this solution works on the current machine only.

Manually Adding the Import Search Path

In order to manually add the import search path, you need to add code to every application created. The code isn’t long or hard to understand, but you must add it to every application that requires the Standard Library or the application won’t be able to access it. Here’s an example of the code you need.


import sys


In this case, my copy of the Standard Library is located in C:Python26Lib, which is the default setup. You need to change this value to match your system. After you make the change, you can verify that it’s correct by using the following code.


print sys.path[len(sys.path)-1]


All that this code does is display the last path added to sys.path. If you see the appropriate path, you know you’re ready to go.

Modifying the File

It’s less convenient to modify the file than it is to use the other two techniques, but you’re also sure that every application will see the path addition when you modify Of course, if you reinstall IronPython, it will overwrite your, and you’ll need to remember to make the change again. As previously mentioned, the file is located in the Program Files IronPython 2.6Lib directory of your machine. Open this file with your editor and add the following code to the top of the file:


import sys


Make sure you change C:Python26Lib to match the location of the Standard Library on your machine. This example uses the default location. After you save the file, restart the interpreter and you should see the path added to the sys.path attribute.

An interesting side effect of using the file is that the Standard Library path will appear before the IronPython paths, which means that the Python Standard Library receives preferential treatment. Remember that you can always tell the interpreter not to load the file by using the –S command line switch.

Latest News

Digital Marketing for Beginners

Digital marketing for starter, Let to basic learning about connecting with your audience in the right place at the...

More Articles Like This