Welcome to Blogs @ Andrew Qu
Blog Index
All blogs
Search results

Python Plugin for Visuial Studio 2010


Introduces the Python Plugin for Visual Studio 2010


Python Tool for Visual Studio (http://pytools.codeplex.com/) is a free and open source plugin for Visual Studio 2010. The plugin essentially turns Visual Studio into a Python IDE. You will get intellisense on Python code and Django. There are pre-configured Python and Django project templates as well.

Installation is very easy. Simply download the installer from http://pytools.codeplex.com/releases. The downloaded file will be PTVS 1.5 Beta 1.msi (the name may be different for a later release). Close any Visual Studio 2010 windows and run the installer. After the installation, verify the result by starting Visual Studio 2010. From the menu bar, select [File] -> [New] -> [Project]. If you can get to the screen shot below, the installation is successful.

Summary of Features
  • Intellisense
  • Code auto-completion
  • Class view
  • Right click, go to definition
  • Find all references to a function, variable or keyword
  • Rename a variable, change all instances
  • Extract a number of lines of code into a local function with optional “enclosure” variable.
  • Add imports, remove unused imports
  • An interactive window to execute Python code. More on this later.
  • Step by step source code debugging. Just like debugging C/C++ codes.
  • Performance profiling (for Visual Studio Ultimate or Enterprise).
  • Many other features. For a full list, see http://pytools.codeplex.com/documentation
A Simple Example

We will use the plugin to create a simple Python application.

  1. Start Visual Studio 2010. Click [File] -> [New] -> [Project]. Refer to the screen shot in “Installation” section.
  2. In the “New Project” window, select [Other Languages] -> [Python] -> [Python Application] (on the right pane).
  3. Give the project name as “PyApp1”, select a path and click [OK]
  4. A project will be created as shown in this screen shot:
  5. To run the program, simply press [F5]. But you cannot see much since the Console Window disappears so quickly.
  6. Add some code as shown in the following screen shot:
  7. While you type, you will see intellisense and auto-complete in action.
  8. Press [F5] to run. You should see the console screen flashes. This will be fixed using the Interactive Window.
The Interactive Window

The Interactive Window is used to execute python code.

  • To start the Interactive Window, in the program menu, click [View] -> [Other windows] -> [Python 64-bit 2.7 Interactive].
  • Once up, you can move, resize and dock the window
  • In the Interactive Window, you can type any Python code and get executed instantly.
    For example, try print(‘Hello Python!’);
  • To run the project in the Interactive Window, click [debug] -> [Execute Project in Python Interactive] as shown in this screen shot:

    This will also make the Interactive Window visible if it is originally hidden.

Source Code Debugging

Source code debugging is the same as other languages in Visual Studio. Therefore, if you are familiar with Visual Studio, then it is very easy. For those not familiar with Visual Studio, the following are some quick tips:

  • Click in the left margin to set/unset break points
  • [F5] to start source code debugging
  • [F10] step over the current line
  • [F11] step into a function
  • You can add variables to the watch window
  • Hover the mouse over a variable to see its current value

*** END ***

Ads from Google
Dr Li Anchor Profi
Engineering anchorage plate design system
©Andrew Qu, 2014. All rights reserved. Code snippets may be used "AS IS" without any kind of warranty. DIY tips may be followed at your own risk.