# Friday, June 26, 2009
« OMG I love recessions! | Main | Oh man Jeff is right, RegexBuddy is my b... »

I've been using IronPython as of late, not a whole lot, but more and more - and I want to do things the Pythonic way using the built in Python libraries whenever possible rather than .NET BCLs.  I've been using REPL mostly, but I'm starting to do more and more in Python, so I've started using SharpDevelop mainly because it supports IronPython out of the box and is a much smaller download than IronPython Studio.

The problem I had was getting access to the standard Python libraries from SharpDevelop, it appears that SharpDevelop only ships with the IP interpreter and not the Python libraries.  The regular IP install does ship with all the libraries, so how can we get SharpDevelop to use them?  Also, how do we get SharpDevelop to use the latest version of IP that I have installed on my system?

Start an IP project in SharpDevelop.  Remove all references to IronPython from the project (assembly ref).  Add a new reference browsing to your latest installed version, mine is in C:\Program Files\IronPython 2.0.1.  Add a reference to IronPython and IronPython.Modules. In SharpDevelop go to Tools | Options | Tools | Python, and browse to ipy.exe in your IP install directory.

Now that we have a working SharpDevelop IP environment running the latest version, lets go ahead and use some Python libs!  Notice how I explicitly set the Python libs path.

import sys
sys.path.append(r'C:\Program Files\IronPython 2.0.1\Lib')

import os.path

def walkDir(arg, dirname, names):
	print dirname

os.path.walk(r'C:\', walkDir, '')
Friday, June 26, 2009 2:47:14 PM (GMT Standard Time, UTC+00:00)
Adding a specific absolute location to sys.path makes your application dependent on IronPython 2 being installed in that specific place (e.g. on x64 Windows IronPython will be installed in "C:\Program Files(x86)\IronPython 2.0.1\Lib").

I prefer to include the standard library, or just the parts I need, within my project.
Name
E-mail
(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview