I’ve been getting to know IronPython a little lately and one of the first things I wanted to know was how to debug IronPython in an IDE. Since I use Visual Studio 2008 at work, I thought it would be a good start. I searched Google and found a text representation of the steps involved over at Harry Pierson’s blog.
I found it pretty simple to do and somewhat useful for longer scripts. It will be nice in the future to have first class support for IronPython in Visual Studio 2010.
You should have IronPython 2.0 Final and Visual Studio 2008 Professional or Better* installed to complete this demo.
Create a python file to debug:
1 2 3 4 5 6 7 8 | #debug.py class Foo: def __init__(self, name=None): self.name = name if __name__ == "__main__": f = Foo("LVS") print f.name |
From Visual Studio, open the IronPython executable (ipy.exe). If it doesn’t do so for you, add the ipy.exe as an existing project.
From the Solution Explorer, right-click on Properties and set the Command Arguments property. Use “-D” to tell ipy.exe to create debugging output, “-i” to start an interactive session at the end of debugging and add the full path to the script you made before.
Click Ok.
Open the script you created earlier in Visual Studio and place breakpoints as desired.
Run the script in debug mode (F5).
If you added the “-i” argument in step 3, after the last breakpoint is released it will launch an interactive session for you. You will be able to inspect your script at this point, much like the immediate window in Visual Studio.
* I tried this in the Visual Studio 2008 Team Developer Edition and the Visual Studio Express Edition. The Express Editions do not work as they don’t allow you to open the ipy.exe as a solution item. Sorry “hobbyists”, we’ll see if the Express sku’s of Visual Studio 2010 will target IronPython / IronRuby.




