微軟的最佳祕密之一-適用於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