Using Python Tools for Visual Studio

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.

Installation

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

Usage

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

Wrap Up

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.

Top White Papers and Webcasts

Live Event Date: March 19, 2015 @ 1:00 p.m. ET / 10:00 a.m. PT
The 2015 Enterprise Mobile Application Survey asked 250 mobility professionals what their biggest mobile challenges are, how many employees they are equipping with mobile apps, and their methods for driving value with mobility.
Join Dan Woods, Editor and CTO of CITO Research, and Alan Murray, SVP of Products at Apperian, as they break down the results of this survey and discuss how enterprises are using mobile application management and private …

On-demand Event
Event Date: February 12, 2015
The evolution of systems engineering with the SysML modeling language has resulted in improved requirements specification, better architectural definition, and better hand-off to downstream engineering. Agile methods have proven successful in the software domain, but how can these methods be applied to systems engineering? Check out this webcast and join Bruce Powel Douglass, author of Real-Time Agility, as he discusses how agile methods have had a tremendous …