A Lap Around Python in Visual Studio 2017

We’re delighted to announce that our rich Python toolchain is fully available in Visual Studio 2017. Installation of Python tools, interpreters, runtimes, and numerous other features are directly integrated into the Visual Studio 2017 installer. Just select the Python development or Data science and analytical applications workloads, both of which let you select specific interpreters like Anaconda and also provide a variety of productivity features:

  • Cookiecutter template support, so you can create projects from dozens of templates hosted on GitHub with a few clicks.
  • Azure cloud service tools, including template to augment existing apps and create new ones that use the latest Azure services ranging from SQL Databases to Data Lake.
  • Python native development tools to write high-performance C++ extensions for Python.
  • Support for code cells and a Jupyter Notebook-like Ctrl+Enter cell execution experience.

In addition, for the first time we’ve localized Python tools into the same 14 languages as Visual Studio, making for a seamless experience across the entire IDE.

All the tools in one place

Let’s take a deeper look into the Python development workload in Visual Studio 2017. (For more on the Data science and analytical applications workload, see Shahrokh Mortazavi’s post, Build Intelligent Apps Faster with Visual Studio. You can also find full documentation for the Python tools at Working with Python in Visual Studio.)

Python Workload

When you select the Python development workload in the Visual Studio installer, either with a new install or modifying your existing installation, you of course get core Python language support including IntelliSense, projects, local and remote debugging, profiling, unit testing, and an integrated REPL environment. Then you can easily select a variety of options as shown on the right side of the installer, including interpreters and specific toolsets. Let’s take a quick look at these.

Python web support

Do you work on Django, Flask, or Bottle apps in Python? Or perhaps another framework? By adding Python web support, you get templates for these languages and the Visual Studio HTML editor with JavaScript (and TypeScript) support. You will also be able to easily publish web sites to Azure through the integrated tools.

Python native development tools

The Python native development tools component includes everything you need to build C++ extension modules, or even build CPython from source. You will get C++ project support and templates, mixed-mode debugging, as well as the latest compiler and the Visual C++ compiler required for compatibility with Python 3.5 and later. You can experience all this for yourself with our Creating a C++ Extension for Python walkthrough.

Python IoT support

The Python IoT support option includes tools needed for writing apps in Python for Windows IoT Core. Note that you’ll also need to download the Python UWP SDK, which is not available through the Visual Studio installer.

Python and Anaconda distributions

Although you can edit Python code quite comfortably without an interpreter, you always need to install a Python interpreter to run it. Previously, this was something you had to do separately from installing the Python tools in Visual Studio, but not for Visual Studio 2017 you can select from a variety of interpreters right in the installer. For example, if you’re just getting started you can just use the Python 3.6 default. Alternately, if you know that you want to use Python 2.7, or want the scientific tools in an Anaconda distribution, those options are readily available as well. And if you already have Python installed, you can easily point Visual Studio to use that environment as well.

Cookiecutter Template Support

Cookiecutter is a popular Open Source templating engine that lets experts easily create highly customizable templates to help other users get started on a project with customized boilerplate code. With Cookicutter integrated directly into Visual Studio, you can more quickly stand up apps, prototype experiences that integrate different services, and try out new frameworks.

You can search, install, and generate projects from Cookiecutter templates within Visual Studio using the Cookiecutter Explorer tool. The community has created several web app templates for Django and Flask, and recently we have seen an increasing number of templates for data science and machine learning.

Jupyter Interactive

Recommended templates make it easy for you to discover Azure templates. We have worked several Azure teams to provide rich templates spanning scenarios ranging from High Performance Computing (HPC) using Azure Batch and Data Lake Store to Internet of Things (IoT) with Azure IoT Hub to web development with Azure Web App. The tool also checks if updates are available for an installed templates and prompt accordingly.

Template description and links to issues, and documentations are surfaced up front to help you navigate to the relevant material on Github faster. All searches are live, so you are getting the latest template information and code from Github.

Jupyter Interactive

A form UI makes is simple to add context like database connection strings, subscription ID, and provide various config settings and preferences. The result is a project that’s tailored to your context so you can get started on the business logic faster. Check out our detailed post for more details. Template developers can also provide helpful descriptors for each of their context variables in the cookiecutter.json file. These descriptions are shown as tooltips in Visual Studio tool.

Working with Jupyter Notebooks

Many developers spend much of their time in the Python REPL experience, and Python in Visual Studio 2017 makes it even more powerful with the ability to debug and profile Jupyter notebooks directly in the Visual Studio IDE.

To work with a notebook, simply download your IPYNB file as a .py file and open it in Visual Studio. You’ll see that markdown cells have been turned into comments and each cell is collapsible and expandable. To run a cell, click anywhere in the cell and press Ctrl+Enter, just like you do in notebooks, which runs the cell in the the Python interactive window.

Jupyter Interactive

You can add code cells by marking them with #%% and create as many interactive windows as you like, with a different Python environment for each one. If you have the Anaconda distribution installed, and you have been working on an online notebook service like Azure Notebooks, you may be able to run your code without installing any additional package by simply selecting Anaconda as your REPL environment.

Localization

For the first time, Python support for Visual Studio is available in all 14 languages that Visual Studio itself supports.

Localization

Choose the language packs you wish to install using the Visual Studio installer, and switch to your language of choice across the entire IDE, including the Python tools, by using Tools > Options > Environment > International Settings in Visual Studio.

Language Packs

Language Options

Looking Ahead

With localization of the Python tools complete, we’ll now be focusing on making our tools accessible over the next few months with better keyword navigation, high contrast support, and narrator friendliness. Some of these improvements have already made their way into the current release. We’re also improving Azure App Service deployment and designing features for data scientists who might desire more overlap between Python and R tools. We’d also love to hear what features are important to you! Let us know by filling or upvoting a Github issue. For more frequent updates on our future progress, check out the Microsoft Python Engineering blog.

Usman Anwer, Program Manager II, Data Science Tools
@uanwer

Usman works on Python and R Tools for Visual Studio and the Azure Python SDK. Previously, he was on the Developer Ecosystem and Platform team in Windows and Devices Group, where he worked on the Universal Windows Platform (UWP), UWP on Xbox, Windows 10 Bridge for Desktop Apps, and putting open source software in Windows.