Python in Visual Studio

Visual Studio is a pretty capable IDE for writing Python. In this post, I am writing down some simple first steps to enable Python support in Visual Studio, and some benefits that you can get from Visual Studio when writing in Python.

Installation

1. Download Visual Studio from the website. You can use either the FREE versions as well.

http://www.visualstudio.com/downloads/download-visual-studio-vs

If you are looking for the free version, you can choose either Visual Studio Express 2013 for Web or Visual Studio Express 2013 for Windows Desktop.

2. Download Python Tools for Visual Studio (from Microsoft)

http://pytools.codeplex.com/

Usage

1. Create new project

New Project

2. Write codes

3. Run

Run

Something you can get when writing Python in Visual Studio

Intellisense

Intellisense works with both built-in Python functions and external packages (of course you will have to install the package first).

Python Intellisense in Visual Studio

Full debugging experience

  • Compile error listing & highlighting
  • Break on exception

Break on Exception in Visual Studio

  • Breakpoint, step through code
  • View/Edit local variable

Locals window

Immediate window to write in interpreter mode

Immediate Window

Install new packages (e.g. Theano, nltk, scipy, numpy) directly inside the IDE using pip, easy_install or conda

Those package installation tools also handle automatic dependency discovery (e.g. installing Theano will also install scipy).

Installing Python packages in Visual Studio

Source-control integration (e.g. TFS, Git, SVN)

You can view your change list, diff each files, update, commit, pull, push, etc. directly inside Visual Studio.

Python Source Control in Visual Studio

 

More information

http://www.i-programmer.info/news/216-python/7888-python-tools-for-visual-studio-gets-new-focus.html

“An error occurred while creating the WebJob schedule”

Azure WebJob has been very helpful to help me running small automated tasks without the hassle of creating VMs or worker roles. Moreover, if you are using a recent version of Visual Studio (from Update 3, I think), you will also get some tooling support for publishing WebJob to Azure Website directly from inside the IDE. It is much more convenient than the old way: building, zipping, going to the portal, deleting the old build and uploading the new one.

However, I then got a strange problem while publishing the WebJob of one project. The error message simply said: “an error occurred while creating the WebJob schedule,” which is not useful for finding a solution at all. I have tried to search around the Internet for a solution, but cannot find any. Even stranger, I can publish that project normally to my staging websites, but not to the production one.

Eventually I found out that I have not set up any deployment credentials for my production Azure Website, and setting one solve the problem completely. I guess the tooling need that credentials to upload the WebJob’s binaries to the website.

I cost me days and days, and I found the solution accidentally after I had tried to connect to the Website using FTP, which requires deployment credentials. I hope this blog post will save you sometime should you got the same problem. I also hope that the tooling will show better error messages next time.