Scott Hanselman

One of Microsoft's Best-Kept Secrets - Python Tools for Visual Studio (PTVS)

July 2, '13 Comments [78] Posted in Open Source | Python
Sponsored By
Python Tools for VS

I've talked some about the sweet support for node and PHP in Azure. You can also File | New | Node.js express application in WebMatrix, or run WordPress and get intellisense as well.

"I installed windows just so i can use PTVS" - Comment on Hacker News

But I'm consistently shocked that folks forget about Python at Microsoft. I am a C# person, myself, but the Developer Division at Microsoft loves their languages. C++, VB, C#, F#, etc and they aren't messing about when they get serious about a language.

One of the least-known and most-kick-butt free products we have is PTVS - Python Tools for Visual Studio. Whether you're just interested in learning Python or you're a hardcore PhD who wants mixed-language Python and C++ debugging or somewhere in between, you gotta check this out. (Seriously, the mixed-mode debugging thing can't be overstressed...)

The Misconceptions

  • Microsoft? Python?  Oh, it must be all about IronPython, that's dead, right?
    • IronPython is a community-run project and just put an 2.7.4 alpha out last month.  PTVS fully supports IronPython, but the most advanced support is for standard CPython!
  • PTVS needs VisualStudio? I don't have any money.
    • PTVS, combined with the Integrated/isolated VS Shell is completely and perpetually free.  And with the advent of VS2013, they've combined them into a single installer: (at bottom of page).

This is Real

Here's my VS2013 after installing PyTools (PTVS). I've got IronPython which is Python running under the .NET CLR, but I've also got Django apps as well as a regular CPython or making a new project from existing code.

Python inside VS

You can see that PTVS knows what Python engines I have installed, and I can easily switch between them. Here you can see that VS is refreshing the auto-completion (intellisense) databases for each version.

A list of Python Interpreters

There's also a complete REPL inside Visual Studio for each:

Python REPL inside VS

Developing Django Apps in Visual Studio

Maybe you're a Django (one of Python's Web Frameworks) web developer, you can use VS to develop your app.

Go File New | Django App, then make a new Python Virtual Environment from the Solution Explorer, and watch Visual Studio freaking installed pip for you (the Python package manager). It's very seamless.

Adding a Virtual Python Environment

Which gives me this:

Python in my VS and I'm FREAKING OUT

Then I right click on "dev" and just like NuGet (except this is Python, so pip) I install django:

Installing Django

Django is massive, so this took a while, but still! And.....I've accomplished Hello World in Django. Well, Hello Django, at least, launched from Visual Studio.

Hello Django

You should feel free to go and run through the whole Django Tutorial if you like and even deploy your app to Azure! You can host Django on a regular Azure Web Site, or a Virtual Machine if you want more control.

You can even interactively debug Python running in Azure on Linux from your Visual Studio instance! Check out Steve do just that at PyCon in this YouTube video.

There's a bunch of great educational and quick start Tutorials on the Python Tools YouTube Channel, they are a great resource to bookmark.

You can attach to remote Python processes over SSL and debug if you like.

Setting up Python Debugging

It's Really Integrated

Let's get real here for a second. Lots of projects plug stuff into Visual Studio. You may have made it this far into the post and be saying "oh, wah wah, this thing sets up some batch files and some syntax highlighting and calls itself a full-featured Python IDE."

Um, no. This is the best of VS and the best of Python and I'm blown away. Check this out. PTVS knows that I'm doing unit testing here and they've integrated Python Unit Testing with the VS Unit Testing UI.

Unit Testing in Python and VS? My heart can't take it!

This is debugging, remote debugging, cross language debugging, tool tips, watches, locals, call stacks, unit testing, full REPL with inline graphics, profiling, cloud publish, best of class CPython support, and so much more.

Nailed it

If you're into Python or knows someone who is, for reals, drink it in and get on board at Check out their samples. They've got Python talking to Kinect, Python talking to Excel and more. Their PTVS Documentation is really good as well.

Just getting started? Well, go Learn Python The Hard Way.

Installing PTVS

Here's the complete install instrucitons. You need VS, the PTVS, and some Python.

PTVS is free

Finally, explore the Resources and Docs for Python Tools for Visual Studio, including, but not limited to Editing, Refactoring, Unit Tests, Django, IPython notebook and Azure cloud computing, Kinect for Python and Pyvot - an Excel to Python bridge.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web
Tuesday, 02 July 2013 08:07:38 UTC
Mind. Blown. This is just awesome!
Glenn Henriksen
Tuesday, 02 July 2013 09:55:06 UTC
Loving this. Can't wait to start Python development with VS!
Pranav Ainavolu
Tuesday, 02 July 2013 10:58:09 UTC
This is awesome!
I am just getting into python and being a c# developer I know that no one makes better dev tools than microsoft.
Tuesday, 02 July 2013 11:15:43 UTC
Wow! I'm impressed the integration is so polished. Thank you for highlighting this. Python is a fun language and having good tooling should make it more fun.
Scott Stubbs
Tuesday, 02 July 2013 11:44:25 UTC
What did you use to install multiple python versions with and manage which ones gets used?
Thanks for the great article!
Tuesday, 02 July 2013 12:26:22 UTC
Too bad there's no similar tooling for Ruby
Tuesday, 02 July 2013 13:09:34 UTC
Awesomeness! I can't wait to try it out!
Tuesday, 02 July 2013 13:14:08 UTC
I was aware of IronPython and the VS Tools but I fell into the category of many who though the tools were just for IronPython. Do you know if the VS Tools for IronRuby are similar in that they provide support for actual Ruby as well as IronRuby?
Tuesday, 02 July 2013 13:35:44 UTC
You are aware that Kane is "applauding" for an absolute disaster that has happened before his eyes for which he's burned quite a lot of money?

Tuesday, 02 July 2013 14:34:05 UTC
Funny you didnt mention the firing/reallocation of py staff in MS from 2010 and how the project dragged for years, pretty sure you did in a podcast at the time.
Matt Freeman
Tuesday, 02 July 2013 14:56:29 UTC
This is very nice! I'll definitely consider this for my upcoming Pluralsight course on Game programming in Python with PyGame!

Thanks Scott!
Tuesday, 02 July 2013 15:06:14 UTC
I've been using this for a few months now, and it's really changed how I feel about using Python. I'm excited for v2.0 to get out of beta, so we can use the VS unit testing framework with Python.

It works really well for mixed-language solutions, too!
Tuesday, 02 July 2013 15:06:38 UTC
What's the relationship with IIS? Would this allow me to build a web app in Python and deploy easily to IIS? I've been investigating doing this with:
John Goodyear
Tuesday, 02 July 2013 15:14:51 UTC
I used PTVS combined with the Integrated VS Shell and is a good way to develop freely.

Although you can also use SharpDevelop with Ironpython which can also help make independent executable files.
Eduard Florinescu
Tuesday, 02 July 2013 15:17:44 UTC
See, I love when you find the hidden gems in Microsoft and highlight them.

It may be hard to see from within our .NET/Ruby/Node.JS walled Ivory Garden, but Python is a BIG deal. Genomic mapping and analysis, BioStatistics, Bioinformatics, manufacturing, game development, etc ...
Tuesday, 02 July 2013 15:37:15 UTC
Fantastic !

The support for developers from Microsoft has been phenomenal, but I really love the way how more and more open source technologies are coming into the mix, off late! :-)
Tuesday, 02 July 2013 15:46:07 UTC
I am waiting for great PHP-Support in VS. Anything to expect on this front?
Mike Devonport
Tuesday, 02 July 2013 15:56:22 UTC
I've been meaning to start doing more Python development recently. This might just get me to start again. I just wish that I had known about this last year when I took my Web Development class, and had to build a Django website.
Preston Moore
Tuesday, 02 July 2013 16:12:50 UTC
Awesome. Coincidentally, I just discovered the Arduino plug in to VS. It's not that I CAN'T program outside the VS's that I don't want to. It's time for everyone to admit that Microsoft pile drove Borland into the ground and emerged victorious with the supreme development environment.
Tuesday, 02 July 2013 16:36:42 UTC
I'm thrilled by VS 2013's new features and seeing this Python support. But I'll echo what's been said above: somebody needs to make basic Java, Ruby and other languages available. I'd do it myself if there was an easy step-by-step. I'd particularly want to get Google Go and Dartlang running, particularly with the new TFS-powered (?) CodeLens functionality.

I suppose, as a starting point: Does CodeLens work with PTVS?

Louis St-Amour
Tuesday, 02 July 2013 17:15:25 UTC
@JohnGoodyear I find that for the most part "integrated" solutions such as IIS-Node, and if there is similar for Python are probably more complicated than needed, and likely not as good as simply installing and using the Application Request Routing (ARR) module for IIS. You can then run your Python/Ruby/NodeJS app with Non-Sucking Service Manager (NSSM) for windows.

In essense you write your app as any other ruby/python/nodejs app, you create a simple cmd/bat file that launches your "webserver" in that platform.. then use nssm to register that command as a windows service (say on port 8001).

From there, you configure IIS to act as a reverse-proxy to your app that runs on a different port connecting to localhost:8001.
Tuesday, 02 July 2013 17:44:14 UTC
Tuesday, 02 July 2013 17:44:28 UTC
Thanks, the timing could not have been better for this post. I have to say I completely forgot about Python at MS, since all IronX went away...

I am just starting a MOOC and was wandering which tools I would use for my Python programming. For those who love Math, learn Linear Algebra through Python programming at The teacher is really passionate, that's the least I can say!
Tuesday, 02 July 2013 18:21:41 UTC
Don't forget about to learn the language
Scott Lance
Tuesday, 02 July 2013 18:33:16 UTC
As a C# junkie I hate Python but =D>
Tuesday, 02 July 2013 18:35:12 UTC
Hi guys, I am a developer on PTVS team. Thanks for all the great feedback! Now, to answer some of your questions...

>> What did you use to install multiple python versions with and manage which ones gets used?

The "Python Interpreters" window that is on the screenshot is a part of PTVS. It doesn't really help you to install them other than directing you to the documentation page explaining what options are there and where to get them, but it's the one you use to see what you have, configure them, choose the one to use by default, open REPLs for them, and monitor progress when PTVS is refreshing code completion database.

>> Does CodeLens work with PTVS?

It doesn't (this functionality is not something that we get automatically - it'd have to be specifically implemented for Python). That said, if you want us to do it, create a feature request at our issue tracker - we do take these very seriously when planning work for new releases (indeed, if you look at what we added in 2.0, it was the three top voted features from our tracker, and two more features that were in top 10 by votes).

>> What's the relationship with IIS? Would this allow me to build a web app in Python and deploy easily to IIS?

You can use the Deploy functionality with local IIS, but the web.config that it'll generate by default is designed for the Azure environment. You can override that by adding your own web.config to the project, but then the burden is on you to configure it for your Python environment (which shouldn't be hard to do if you take the default config and tweak it).
Tuesday, 02 July 2013 19:36:32 UTC
Merci, j'ai bien ri.
Julien Hautefeuille
Tuesday, 02 July 2013 21:00:10 UTC
I love PTVS. It's hands down the best Python IDE I've tried. I'm a fan of IPython Notebook as a REPL, but for building real software, PTVS rocks.
Tuesday, 02 July 2013 23:08:32 UTC
@John Goodyear

A little more on IIS - We created our own Python script for doing a WSGI<->FastCGI gateway for IIS (it's called wfastcgi). That works w/ normal IIS, IIS Express, and Windows Azure Web Sites (where it's already deployed on all of the servers along w/ Python 2.7). It's also available on our downloads page.

It's in PTVS too because within VS we support deployment to Azure where we'll automatically package this up and generate the appropriate web.config to setup and run. There's a tutorial on how to set it up on Azure and the same basic appcmd's will work off Azure to setup normal IIS.

Basically this accomplishes the same thing as Zoo but is much simpler. It has no dependencies beyond a standard Python install and is just a single script that can easily be copied anywhere. Also my initial benchmarks seemed to show this as faster but they certainly weren't exhaustive and YMMV.
Tuesday, 02 July 2013 23:35:38 UTC
The VS version of PyCharm (or IntelliJ with Python plugin)
PyCharm is cross-platform, though, and I have trouble imagining that even VS can compete.
Wednesday, 03 July 2013 00:02:15 UTC
I really like PTVS. I learned Python using PTVS for my Coursera class.
Debra D.
Wednesday, 03 July 2013 00:33:04 UTC
Nameless, try this in PyCharm:

def f(x):
def g(y):
return x + y
return g

a = f(1)(2)
b = f(3.0)(a)
c = f(u'a')(str(b))
d = (a, b, c)[input()]

And see what member completion options it gives you for a, b, c and d. Then do the same in PTVS :)
Wednesday, 03 July 2013 02:15:33 UTC
Wednesday, 03 July 2013 07:32:52 UTC
Django is not that massive...
Wednesday, 03 July 2013 11:56:57 UTC
This just made my day.
If only I knew about this few months earlier, it could have saved me so much work...
Wednesday, 03 July 2013 14:27:55 UTC
The GIF at the end is the best part!!
Hrusikesh Panda
Wednesday, 03 July 2013 14:47:14 UTC
I'm a long time C#/VS developer, and one of the suckers accepting the Google Glass Explorers invite. I was considering doing my app development in Python - I've never used it, but have wanted to take a peek since it's been suggested as a good language for introducing Geeklings to programming. The fact that I can use an IDE with which I'm comfortable makes it a little less intimidating to pick up a new platform AND a new language at the same time.

Thanks for the info, and keep up the (always excellent and entertaining) work!
Wednesday, 03 July 2013 15:32:00 UTC
I've heard about PyTools before, but more as an example of how to write things using VS's language tools since I don't actually know Python.

I haven't looked at it for a few years, though... does the 2.0Beta make use of any VS2012 or 2013 features?

Unfortunately, using it an example of language tools kinda failed as it was for a non-work project that I kinda let die because it ended up looking like it was going to be a much larger project than I initially thought.
Ross Bemrose
Wednesday, 03 July 2013 15:48:23 UTC
Hi Scott,

Does anyone actually use PyTools in the real world? And if yes, then why?

Maybe there's a reason why MS kept it a secret.
Wednesday, 03 July 2013 17:46:07 UTC
Not sure if it's a bug/feature.

After installing this and running VS2012 unit tests for native C++ project the testrunner spends 20-30secs "loading symbols..." for a bunch of python libs - even when there is no python in the project
Wednesday, 03 July 2013 18:24:37 UTC
Now all VS needs is to add world class support for java. Compared to VS, eclipse is horrible.
Wednesday, 03 July 2013 18:49:49 UTC
Fadi - Of course, it's used by lots. It's not a secret. It's been in development for YEARS.
Thursday, 04 July 2013 13:29:55 UTC
This is really cool. I was doing some experiments with IronPython and PythonStudio about 2 years ago and really liked it.
Then I lost track of these project and assumed they were dead by now.
Thanks for bringing them back on the table.
The quality and functionality of this VS integration blows my mind.
Thursday, 04 July 2013 16:56:19 UTC
Is it possible to use python and PTVS to develop windows store applications?
Saturday, 06 July 2013 08:24:08 UTC
Creating Django project requires IIS?
Chatchai Naenudorn
Saturday, 06 July 2013 20:35:48 UTC
Well, i have to say the last place i would expect python support is on vs, this changes the impression i have about microsoft, perhaps they should be more vocal about their work.
Saturday, 06 July 2013 22:07:12 UTC
Glad To Use Python On MS VS :)
Monday, 08 July 2013 11:49:09 UTC
Very cool Scott... I have wanted to learn Python and this gives me a reason to do so since i'm in VS 24/7 lol. I agree with Radu, we just need VS to do Java.. and I'd be in heaven!
Monday, 08 July 2013 15:33:08 UTC
I've programmed C# for 10+ years, but our group just moved to Python/Django. Glad to see you take notice, Scott - hopefully a lot more managers at Microsoft do too. You see, now I don't have to leave my favorite environment - Visual Studio - which is why I'm so glad to see you giving these guys credit! If not for them, I'd be on a Mac with PyCharm, but now I get to stay in Windows and Visual Studio writing Django apps + Typescript, and can still O&M all of my .NET apps - in one place. Seriously, I love to see that Microsoft is getting behind these guys, they deserve more credit and support.
Tuesday, 09 July 2013 05:42:52 UTC
Interesting article but unfortunately, not relevant... until you posted that little gem at the end "Learn Python the Hard Way". That's a fun little introduction to the language and gave me a chance to run through the editor. You're a master at finding interesting stuff on outskirts of the web. Thanks for sharing. :-)
Thursday, 11 July 2013 04:41:34 UTC
I am using beta 2.0 on vs 2012;
too bad it hangs on large python projects:

the previous version for vs 2010 works but realy slow when first opening this large projects
Thursday, 11 July 2013 19:28:05 UTC
This is nice if all you're coding Python for is Windows. Unfortunately, there is a much larger world out there. Microsoft really needs to port Visual Studio to Mac (at minimum) and eventually Linux (gasp!) for this to appeal to the larger Python community.

For now, I'm going to stick with vim, Sublime, PyCharm, IPython, etc.

Tuesday, 16 July 2013 18:36:53 UTC

@indra - this issue has been repro'd & fixed already for RC (late summer). there is also a work around:

Tuesday, 23 July 2013 18:15:07 UTC
Framework 4.5 only have python support or previous versions also compatible.
Tuesday, 30 July 2013 23:19:17 UTC
Visually developing and Python to support Microsoft to thank you.
Monday, 12 August 2013 02:52:13 UTC
Has anyone been able to get pip to install when behind a firewall? NuGet and all the other things in VS2012 works fine, but when i try to get pip to go, it gives me a 407 proxy authentication required error. I added HTTP_PROXY as an Environment variable, but still no joy.
Friday, 16 August 2013 04:47:52 UTC
Never wanting to leave any level of interest and skill out: I would add, for beginners/students, this link:
This site has blown me away - much as your post did.
Friday, 23 August 2013 12:00:55 UTC
@Amir: funny you hate python and love C#, did you notice C# 3 brought to .NET devs A LOT of features available in Python?
Tuesday, 27 August 2013 09:23:40 UTC
You should clarify whether the screenshots you posted is for PTVS with isolated VS Shell. Or is it VS2013 FULL with PTVS. It isn't clear to me.
Thursday, 05 September 2013 19:38:02 UTC
Regarding the proxy problem mentioned above. The workaround is to install pip manually, after which you can add proxy to its config file, as described here:

We're also tracking the feature request to add proxy support to pip bootstrapping:
Thursday, 05 September 2013 19:39:26 UTC
@negaboys: You do not need .NET to run Python applications at all. As for PTVS, it has the same requirement as the version of VS it is targeting (and if you have the corresponding VS installed, you already have the right version of .NET).
Friday, 06 September 2013 00:38:23 UTC
When I try to import libraries like NLTK in the python application, it says unknown type. How do we resolve it? Thanks.
Wednesday, 18 September 2013 14:40:00 UTC
Flask SPA with Knockout.js running in Visual Studio 2013 RC 1 - Booyaaa!
Steven Elliott
Saturday, 21 September 2013 17:22:39 UTC
Is it possible to get a django application running on IronPython? I've been trying unsuccessfully to get this working for a couple days now.

It seems like IronPython has enough subtle differences that running a high complexity application like django is difficult.

If django apps could be portable to IronPython that seems like it would be a crazy win for Microsoft: All you would need is ASP.NET hosting and you could host both .NET and Django projects!
Thursday, 26 September 2013 02:17:49 UTC
Oh, this is great, just loved it! <3 <3 <3
Thursday, 26 September 2013 05:07:00 UTC
Great article! I was actually shocked when I saw the support for Python in Visual Studio. It was enough to get me wanting to pick up python again. I actually blogged about my first experiences with it:

Thanks for the info!
Thursday, 26 September 2013 23:01:20 UTC
PythonToolsIntegrated.exe failed to install on Windows 7 (without Visual Studio 2013), not sure if I need to install VS 2013 first (I don't want to).
Saturday, 28 September 2013 18:30:13 UTC
I am not impressed. I was expecting a REPL built into the IDE, but when I run my python script, a CONSOLE window launches, and my output goes into that console. (It is also scraped and written back to the IDE). I was thinking that there would be an interactive Python output window with a REPL (python prompt).
Warren P
Wednesday, 02 October 2013 18:53:45 UTC
A great alternative to IronPython is pythondotnet:

This allows you to use .NET libraries directly from CPython. You can do stuff like this:

from System.Collections import Hashtable
table = Hashtable()
table["key 1"] = "value 1"

The advantage over IronPython is you also have all python C-extensions available. Rumour has it that you can also call C-python from .NET with this goodness, but I have not tried that.
John Gill
Thursday, 17 October 2013 20:45:47 UTC
Anyone knows why VS2012 gets dog slow when editing a .py file ? It's rather annoying.
Sunday, 20 October 2013 23:24:06 UTC
this setup was surprisingly easy! Thanks!
Tuesday, 22 October 2013 04:52:15 UTC

When I ran it with VS2012 there was a (pytools?) process rapidly eating memory even after I closed VS, don't know if it is connected to your problem though. I downloaded VS2013 ult RC from dreamspark and it ran alot smoother (though now, after I had to reinstall all my programs, when I try to download pytools I get an incompatibility error with VS2013 RC, maybe I just need to search a bit better).

kasper o.
Tuesday, 22 October 2013 20:41:52 UTC
Is it better to use PVTS+Visual Studio or any specialized software such as Anaconda ?
Thursday, 31 October 2013 14:14:35 UTC
python 3.3 is compiled with VS2010, many modules downloaded with pip from pypi look for VS2008. If I use VS2013 (without the other version installed) is this a problem? Any suggestions how to get around it?
Monday, 11 November 2013 17:02:02 UTC
Really A nice PlugIn, Just awsome.
Sunday, 17 November 2013 20:02:28 UTC
Awesome! I already consider VS to be the best IDE out there. Now that it can integrate Python, it is undefeatable!

Now I'm wondering if there is some sort of plug-in for writing Java/Android apps in there too...Hmmmmm....

Thanks Scott!
Brandon Tran
Monday, 18 November 2013 18:44:05 UTC
Visual Studio is a great IDLE & PTVS is certainly a great choice for working with IronPython, but the best Python IDLE has to go to JetBrains for PyCharm, that's one intelligent IDLE.
Tuesday, 19 November 2013 14:25:48 UTC
I installed PTVS and IronPython, and created a Windows Forms app. It runs fine, so now I need to add some controls to the form. I had no idea how to do this, so I pressed F1 hoping to get some help, and the VS2012 IDE crashed (Not Responding).
Dave Semmelink
Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.