Virtual Developer Workshop: Containerized Development with Docker
Microsoft has traditionally shown limited support for most open-source languages. The IronPython project was one of the first to crack open the door, making it possible for other languages like PHP and Ruby to sneak in as well. While IronPython and IronRuby have diminished somewhat, there is a new project that has taken up the open-source mantle.
Python Tools for Visual Studio (PTVS) represents a new direction for a number of the team members formerly working on IronPython. PTVS brings the power of Visual Studio to any number of Python distributions including IronPython. The Python Tools for Visual Studio project is hosted on Microsoft's codeplex site. You'll find a wealth of information including documentation, FAQs, links to videos, and much more.
For this article we used a fresh 32-bit virtual machine version of Windows 7. The best news here is you don't need a full version of Visual Studio to use PTVS. You only need three files to get everything up and running. First you'll need to download and install the Visual Studio Integrated Shell. This gives you all the basic Visual Studio integrated development environment (IDE) tools but no language support. It will take a little while to install all the necessary pieces, so be patient. Figure 1 shows what you'll see when you launch the installer. Uncheck the box labeled "Yes, send information to Microsoft…" if you'd rather not transmit anything.
Microsoft Visual Studio 2010 Shell (Integrated) Installer
Next, you must install a Python distribution. The quickest and easiest way to get lots of Python functionality is to download the free Enthought Python Distribution. For Windows you'll have to upgrade to a paid version if you want native 64-bit support. The good news is you can use the 32-bit free version on 64-bit versions of Windows with no issues. EPD Free comes with Chaco, iPython, Matplotlib, Numpy, Scipy and Traits plus the entire Python standard library.
The last step involves downloading and installing PTVS. You'll find a download link on the front page of the PTVS codeplex site. The installer is distributed as an .msi file and should launch if you double-click on it from Windows Explorer. Once that completes you should be all set. Launch Visual Studio and you should see something like Figure 2.
Visual Studio 2010 Shell - Get Started
Click on New Project and you'll see something like Figure 3.
Visual Studio 2010 Shell - New Project
If you're a visual learner, you'll want to check out the videos produced by the PTVS team on YouTube. There are several covering the basic usage and how PTVS integrates with the Visual Studio environment. Python is an interpreted language and, as such, provides an interactive facility for typing in commands and getting immediate feedback. PTVS accommodates this with an interactive window available through the View Other Windows menu or by using the Alt-I keyboard shortcut.
One of the really handy things you'll get with Visual Studio is Intellisense. Be aware that it takes almost fifteen minutes on a typical machine for the system to analyze the Enthought distribution, so it might not show up immediately after installation. Once the analyzing and indexing process completes you'll have full access to help for all available Python libraries.
You'll find all the standard Visual Studio debugging tools work as well. Setting breakpoints, examining local variables and stepping through code all work just as you'd expect (see Figure 4). You can also launch your code in the interpreter if you want access to the command line. There are a number of features provided by the interactive window including the ability to change scope from the main module to another module. There's Intellisense available in the interactive window for live objects, so you can quickly see the available methods on a user-defined class.
Standard Visual Studio Debugging Tools
In part two of this series we'll look at using PTVS along with Numpy and Scipy for doing scientific calculations and the Pyvot tool for interacting with Excel. PTVS is a great way to get started learning the Python language, especially if you're already familiar with Visual Studio.