微软的最佳秘密之一-适用于Visual Studio的Python工具(PTVS)

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.

我已经谈到了Azure中对节点和PHP的出色支持。 您还可以File | 新增| Node.js在WebMatrix中表达应用程序,或者运行WordPress并获得智能感知。

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

“我安装了Windows只是为了可以使用PTVS”-评论黑客新闻

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.

但是我一直感到震惊,因为人们忘记了Microsoft的Python。 我本人是C#人,但是Microsoft的开发人员部门喜欢他们的语言。 C ++,VB,C#,F#等,当他们认真对待一种语言时,他们不会在意。

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...)

我们拥有的最鲜为人知的免费产品之一是Visual Studio的PTVS- Python工具。 无论您是只是对学习Python感兴趣,还是是想要混合语言Python和C ++调试或在两者之间进行调试的铁杆博士,都必须检查一下。 (严重的是,混合模式调试工作不能过分强调...)

误解 (The Misconceptions)

  • Microsoft? Python?  Oh, it must be all about IronPython, that's dead, right?

    微软? Python? 噢,那一定是关于IronPython的全部了,对吧?

    • 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!

      IronPython是一个社区运行的项目,上个月刚刚发布了2.7.4 alpha。 PTVS完全支持IronPython,但最高级的支持是标准CPython!

    Microsoft? Python?  Oh, it must be all about IronPython, that's dead, right?

    微软? Python? 噢,那一定是关于IronPython的全部了,对吧?

  • PTVS needs VisualStudio? I don't have any money.

    PTVS是否需要VisualStudio? 我没有钱。

    • 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).

      PTVS与集成/隔离VS Shell结合使用是完全免费的。 随着VS2013的问世,他们将它们组合为一个安装程序: https ://pytools.codeplex.com/releases(在页面底部)。

这是真的 (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.

这是安装PyTools (PTVS)之后的VS2013。 我有IronPython,它是在.NET CLR下运行的Python,但我也有Django应用程序和常规CPython,或从现有代码创建新项目。

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.

您可以看到PTVS知道我已经安装了哪些Python引擎,并且我可以轻松地在它们之间进行切换。 在这里,您可以看到VS正在刷新每个版本的自动完成(智能)数据库。

A list of Python Interpreters

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

每个Visual Studio都有一个完整的REPL:

Python REPL inside VS

在Visual Studio中开发Django应用 (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.

也许您是Django(Python的Web框架之一)的Web开发人员,则可以使用VS开发应用程序。

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.

转到新文件| Django App,然后从解决方案资源管理器中创建一个新的Python虚拟环境,并观看Visual Studio为您抓取已安装的pip (Python包管理器)。 非常无缝。

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:

然后我右键单击“ dev”,就像NuGet一样(除了这是Python,所以pip)我安装了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.

Django非常庞大,因此花了一段时间,但还是! 而且.....我已经在Django中完成了Hello World。 好吧,至少,Hello Django是从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.

如果您愿意,甚至可以将您的应用程序部署到Azure可以随意遍历整个Django教程! 您可以将Django托管在常规Azure网站上,如果需要更多控制权,则可以托管在虚拟机上。

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.

您甚至可以从Visual Studio实例交互式调试在Linux上的Azure中运行的Python! 观看YouTube视频中Steve在PyCon上所做的

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

Python工具YouTube频道上有很多很棒的教育性和快速入门教程,它们是书签的重要资源。

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

您可以根据需要通过SSL附加到远程Python进程并进行调试。

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."

让我们在这里变得真实吧。 许多项目将东西插入Visual Studio。 您可能已经在帖子中说了这么多,然后说:“哦,哇,这东西设置了一些批处理文件和一些语法突出显示,并称自己为功能齐全的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.

不。 这是VS最好的,也是Python最好的,我被吓死了。 看一下这个。 PTVS知道我在这里进行单元测试,他们已经将Python单元测试与VS单元测试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.

这是调试,远程调试,跨语言调试,工具提示,监视,本地,调用堆栈,单元测试,带有嵌入式图形的完整REPL,性能分析,云发布,一流的CPython支持等等。

Nailed it

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.

如果您喜欢Python或认识某个真正的人,请喝酒并加入https://pytools.codeplex.com 。 查看他们的样本。 他们有Python与Kinect对话,Python与Excel对话等等。 他们的PTVS文档也非常好

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

刚开始? 好吧,去学习Python The Hard Way

安装PTVS (Installing PTVS)

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

这是完整的安装工具。 您需要VS,PTVS和一些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.

      最后,探索适用于Visual Studio的Python工具资源和文档,包括但不限于编辑重构单元测试Django,IPython笔记本和Azure云计算Kinect for PythonPyvot-Excel to Python的桥梁

      关于斯科特 (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.

      斯科特·汉塞尔曼(Scott Hanselman)是前教授,前金融首席架构师,现在是演讲者,顾问,父亲,糖尿病患者和Microsoft员工。 他是一位失败的单口相声漫画家,一个玉米种植者和一本书的作者。

      facebook
      twitter
      subscribe
      About   关于 Newsletter 时事通讯
      Hosting By 主持人
      Hosted in an Azure App Service

      翻译自: https://www.hanselman.com/blog/one-of-microsofts-bestkept-secrets-python-tools-for-visual-studio-ptvs