Microsoft Visual Studio as a Python IDE

If you’re running the Windows operating system, and doing any type of software development work in VB.NET, C#, PowerShell, MVC, JavaScript, or anything else, you’re most likely familiar with the Visual Studio Integrated Development Environment (IDE). Visual Studio has been known for a long time, as an enterprise-class, reliable, and most importantly extensible software development tool.

In earlier iterations of the product, Microsoft offered free, stripped down “Express” editions of Visual Studio. Providing free development tools encouraged contributions to the open source community, and most importantly, encouraged software development on the Microsoft platform. With the advent of Visual Studio 2015 on July 20th, 2015, Microsoft offered a new “Community” edition of Visual Studio.

Visual Studio 2015 Editions

Visual Studio 2015 Editions

I’ve already written another article about PowerShell Tools for Visual Studio, but I wanted to also point out that Visual Studio can be used to develop in other languages, such as Python. Microsoft is authoring a Python Tools for Visual Studio (PTVS) Extension, which adds a whole host of Python-related features to the Visual Studio environment. Most importantly, you’ll want to check out:

  • Python Project Templates
  • Python File Types
  • A Python Environments window
  • Python Interactive window
  • Python Debugging
  • Python Syntax highlighting
  • Python Intellisense (aka. auto-completion)
Python Tools in Visual Studio 2015

Python Tools in Visual Studio 2015

Python Project Templates

When you create a new Python project in Visual Studio, or add a Python project to an existing Visual Studio solution (“solutions” contain one or more projects, optionally of different types), the PTVS extension adds support for many different types of Python-related projects! Some of these project types include:

Visual Studio 2015 :: Python Tools :: Project Types

Visual Studio 2015 :: Python Tools :: Project Types

When you open a Python Visual Studio project, in the Visual Studio Solution Explorer window, you can see the list of your Python “environments” (separate installations of Python), and the modules that your Python environment references. These module references are somewhat analogous to NuGet packages in a .NET project.

Python Tools for Visual Studio :: Project Structure

Python Tools for Visual Studio :: Project Structure

Python File Types

There are many different types of Python applications, including web, GUI (Tcl/Tk), IronPython (.NET), and command line scripts. Each type of Python application has different types of files that it leverages, and the PTVS extension adds all of these. Check out the screenshot below for a list of all the file types that are added to Visual Studio’s “Add New Item” dialog for Python projects.

Python Tools for Visual Studio :: File Types

Python Tools for Visual Studio :: File Types

Visual Studio Text Editor Enhancements

Intellisense and syntax highlighting are absolutely essential features for any software development environment. Having immediate feedback about syntax errors, simple typos, and having function definitions available at your fingertips are all perfect tools to make you a more productive developer in addition to learning on-the-fly. I’ve always said that context switching is an expensive operation for both computers and humans, and it’s true. The more you have to switch back and forth between your web browser and development tool, the less time you’re actually writing, understanding, and debugging your code. As you can see from the screenshot below, the PTVS support for these essential features is quite awesome in Visual Studio 2015!

Python Tools for Visual Studio :: Intellisense & Syntax Highlighting

Python Tools for Visual Studio :: Intellisense & Syntax Highlighting

Debugging

PTVS :: Debugging

PTVS :: Debugging

Debugging support is present in PTVS as well! You can set breakpoints using the F9 keyboard shortcut, and when a breakpoint is hit, you can hover over a variable to view its contents. Here is an example of using the Python Requests library to perform a HTTP GET request, and viewing the results in the debugging environment.

Thanks to the power of conditional breakpoints in Visual Studio, you can break into the debugging environment, based on custom conditions in your Python code. Standard keyboard shortcuts, such as F10 - Step Over and F11 - Step Into work as expected in Python code.

PTVS :: Debugging :: Step Into

PTVS :: Debugging :: Step Into

Conclusion

If you’re a Python developer on Windows, who’s searching for a good IDE, look no further than Visual Studio!! In fact, if you’re running a different platform on your laptop, desktop, tablet, or other client device, you might want to consider spinning up a Windows virtual machine on the Microsoft Azure platform so that you can take advantage of everything that Visual Studio has to offer. With rich features like syntax highlighting, Intellisense, and debugging, you will almost certainly fall in love with Python Tools for Visual Studio instantaneously!

You can learn more about Python Tools for Visual Studio using the YouTube playlist below, hosted by the Visual Studio YouTube Channel.