One of Microsoft's Best-Kept Secrets - Python Tools for Visual Studio (PTVS)
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...)
- 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: https://pytools.codeplex.com/releases (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.
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.
There's also a complete REPL inside Visual Studio for each:
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.
Which gives me this:
Then I right click on "dev" and just like NuGet (except this is Python, so pip) I install 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.
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.
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.
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.
If you're into Python or knows someone who is, for reals, drink it in and get on board at https://pytools.codeplex.com. 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.
Here's the complete install instrucitons. You need VS, the PTVS, and some Python.
- If you have no Visual Studio installed, go get the FREE PTVS that includes the Visual Studio Shell. That's "PyToolsIntegrated" at the middle of this page. Then get a copy of Python.
- If you already have VS 2010, VS 2012, or VS 2013, go get PTVS for your version. The VS2013 version is the best and has a lot of fixed bugs. I installed PTVS along with Python 3.3 for Windows.
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.
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.
I am just getting into python and being a c# developer I know that no one makes better dev tools than microsoft.
Thanks for the great article!
It works really well for mixed-language solutions, too!
Although you can also use SharpDevelop with Ironpython which can also help make independent executable files.
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 ...
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! :-)
I suppose, as a starting point: Does CodeLens work with PTVS?
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 www.yourapp.com to localhost:8001.
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 https://www.coursera.org/course/matrix. The teacher is really passionate, that's the least I can say!
>> 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).
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.
PyCharm is cross-platform, though, and I have trouble imagining that even VS can compete.
return x + y
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 :)
If only I knew about this few months earlier, it could have saved me so much work...
Thanks for the info, and keep up the (always excellent and entertaining) work!
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.
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.
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
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.
too bad it hangs on large python projects:
the previous version for vs 2010 works but realy slow when first opening this large projects
For now, I'm going to stick with vim, Sublime, PyCharm, IPython, etc.
@indra - this issue has been repro'd & fixed already for RC (late summer). there is also a work around:
This site has blown me away - much as your post did.
We're also tracking the feature request to add proxy support to pip bootstrapping:
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!
Thanks for the info!
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.
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).
Now I'm wondering if there is some sort of plug-in for writing Java/Android apps in there too...Hmmmmm....
Comments are closed.