Using Sho with Python Tools for Visual Studio (PTVS)

If you're looking for a great integrated development environment (IDE) for Sho, Python Tools for Visual Studio (PTVS) is a perfect fit.  PTVS is a plugin for Visual Studio 2010; you can get the free VS Shell if you don't have Visual Studio already. PTVS gives you an interactive REPL with intellisense, great editing capabilities such syntax highlighting, automatic indents, intellisense, etc., as well as Python debugging, with some project management features to boot.  A screenshot of using Sho with PTVS is below.

Downloading and Installing PTVS and Sho

  1. You'll first need to install IronPython 2.7 from the IronPython page.  When running the installer, be sure to uncheck the "Visual Studio" options; those conflict with PTVS.  Note that PTVS debugging/interactive windows will not work properly with earlier versions of IronPython (pre 2.7) - you can still edit code and do .net debugging, but for the full experience you'll want IronPython 2.7.
  2. Next install Sho 2.0.5 (the version targeted to IronPython 2.7). You'll need to first uninstall any previous Sho installations.
  3. Download and install the PTVS plugin from the PTVS project page. Note that if you don't have Visual Studio 2010 already, you can see various means of getting it (including several free options) in the "Getting Visual Studio" section of the PTVS install page
  4. Start Visual Studio, and go to Tools->Options->Python Tools->Interpreter Options. Set the "Default Interpreter" to be "IronPython 2.7."  If you're on a 64-bit machine and want to use all of your memory for Sho computations, set it to "IronPython 64-bit 2.7"

Setting up Sho for PTVS

If you're a regular Sho user, you'll probably want to add the importing of the Sho libraries directly into the startup of the PTVS. To do this, you'll first create a startup file, which I like to call "" - the contents are below:

# - Sho startup file for PTVS
import sys
sys.path.append("c:/Program Files/Sho 2.0/Sho")
from sho import *

Note that you'll have to set the path to point to the "shoshodir", which you can find by evaluating shoshodir in the Sho console. To specify this as the startup file for the IronPython interpreter, go to Tools->Options->Python Tools->Interactive Windows, and under "Startup Script" specify the full path to (or whatever you chose to call it). If you don't want to create/use this startup file, you can manually execfile or just include the lines above in any scripts from which you want to use Sho commands or libraries.

You can now click on Tools->Python Tools->IronPython 64-bit 2.7 Interactive, and you'll get a new REPL with all the Sho commands at your fingertips.

Debugging Sho code from PTVS

There are two styles of debugging for IronPython - Python debugging and .NET debugging. Python debugging lets you look inside Python classes and examine variables, just as you would with pdb, but doesn't let you step into .NET code. .NET debugging does let you step into and examine .NET code, but gives you a more limited Python debugging experience - for instance, members of Python classes will appear as they do in .NET, as part of dictionary, as opposed to the class structure you'd see in Python debugging. In short, if you're mostly debugging Python code, you'll likely want Python debugging; if you're mostly debugging C# (or mixed mode code), you'll want to use .NET debugging.

PTVS is focused on Python debugging; if you want to do .NET debugging see "Using PTVS with the Sho Console" below. To do Python debugging, simply set breakpoints in your code (F9) and then run commands from the Python Interactive window; when your breakpoints are hit, execution will pause, and you can investigate variables, step through, etc.

Using PTVS with the Sho Console

If you're doing mixed mode (Python and C#) development or just prefer the Sho Console for your interactive sessions, you can still take advantage of PTVS's fantastic editor as well as .NET debugging. As described above, .NET debugging lets you set breakpoints in both Python and C# code, step into C# or Python code, etc., at the cost of not being able to look inside Python objects with the same convenience as Python debugging (above).

To debug code in Sho Console, you'll need to first attach to the process via Debug->Attach to Process in Visual Studio. This will bring up a list of processes and their IDs; pick the appropriate "shoconsole.exe" process. If you have more than one you can evaluate System.Diagnostics.Process.GetCurrentProcess().Id in the console to find out the Process ID for the one you wish to debug. You can then load up the relevant Python and C# files you wish to debug in Visual Studio, and set breakpoints wherever you wish. When you execute code in the console that results in one of these breakpoints being hit, execution will pause and control will go to Visual Studio; at this point you can step through code, step into code, etc., as you normally would in VS.