Python Developer Tools from Microsoft. Beginning of work

Original author: Dan Taylor
  • Transfer
  • Tutorial
For the past few years, Microsoft has worked to add support for Python developer tools to one of our most popular products: Visual Studio Code and Visual Studio. This year it all worked. In this article, we will introduce you to the Python developer tools in Visual Studio, Visual Studio Code, Azure, etc. Look under the cat!



Python is one of the fastest growing programming languages, which is addressed to both beginners and experienced developers. Its popularity is due to easy-to-learn semantics and a wide range of applications, ranging from writing scripts to creating web services and machine learning models.

More information and the latest news about Python at Microsoft can be found on the Python at Microsoft blog .

Visual studio code


The open source Python for Visual Studio Code extension includes other publicly available Python packages to provide developers with opportunities for editing, debugging, and testing code. Python is the fastest growing language in Visual Studio Code, and the corresponding extension is one of the most popular in the Marketplace section on Visual Studio Code!

To get started with the extension, you must first download the Visual Studio Code, and then, following our guide Getting started with Python , install the extension and configure the basic functions. Consider some of them.

First you need to make sure that Visual Studio Code uses the correct Python interpreter. To change the interpreter, simply select the desired version of Python in the status bar:



The selector supports many different interpreters and Python environments: Python 2, 3, virtualenv, Anaconda, Pipenv, and pyenv. After selecting the interpreter, the extension will start using it for the IntelliSense function, refactoring, analyzing, executing, and debugging code.

To run the Python script locally, you can use the “Python: Create Terminal” command (“Python: create a terminal”) to create a terminal with an activated environment. Press CTRL + Shift + P (or CMD + Shift + P on Mac) to open a command prompt. To execute a Python file, simply right-click on it and select Run Python File in Terminal:



This command will launch the selected Python interpreter, in this case the virtual Python 3.6 environment, to execute the file. :



The Python extension also includes debug patterns for many popular application types. Go to the “Debug” tab and select “Add Configuration ...” in the debug configuration drop-down menu:



You will see ready-made configurations for debugging the current file connecting to a remote debug server or to the corresponding Flask, Django, Pyramid, PySpark or Scrapy application. To start debugging, select the configuration and press the green Play button (or the F5 key on the keyboard, FN + F5 on the Mac).

The Python extension supports various code analyzers for which you can customize the launch after saving the Python file. PyLint is enabled by default, and another analyzer can be selected using the “Python: Select Linter” command (“Python: select code analyzer”):



That's not all: support for refactoring, as well as unit testing using unittest, pytest, and nose. Plus, you can use Visual Studio Live Share. for remote work on Python code together with other developers!

Python in Visual Studio


Visual Studio supports most of the features of Visual Studio Code, but also offers all the useful features of an integrated development environment that allows you to perform more operations without using the command line. Visual Studio also provides unparalleled capabilities for working with hybrid Python and C # or C ++ projects.

To enable Python support in Visual Studio on Windows, you must select the Python Development workload and / or the Data Processing and Analysis Applications analytics workload in the Visual Studio installer:



You can install different versions of Python and Anaconda by choosing them in the menu of additional components (see the right part of the screenshot above).

After installing the Python workload, you can start working by creating a Python project in the section using the File -> New Project menu (select Python in the list of installed components):



To create an application from scratch, open the Python application template and start writing code. You can also create a project using existing Python code as a basis or using web templates for Flask, Django and Bottle. Read our Guidelines for Flask and the Guidelines for the Django , to get detailed information on developing with these platforms and Visual Studio web applications.

If you have a data processing and analysis workload installed, you can also use templates for machine learning projects using Tensorflow and CNTK.
After the project is created, you can manage virtual and conda environments using the Python Environments node in the Solution Explorer and the Python environment window. By right clicking on the active Python environment and selecting the appropriate menu item, you can install additional packages:



Visual Studio truly demonstrates its capabilities when using Python with other languages. You can combine Python and C ++ projects to create a solution, or even embed .py files in C ++ or C # projects!

You can even debug code in both languages ​​in the same session, for example, switching from C ++ debugging type to Python / Native:



You can read more about inserting Python into C ++ applications in the Insert Python publication into a C ++ project.in the python blog.

In addition, Visual Studio includes the Python Profiler and supports Python unit testing in the Test Browser.

Python to Azure


The Azure SDK for Python lets you create, manage, and interact with services in Azure. The Azure CLI command line is written in Python, so you can also accomplish almost everything that it can do at the program level using the Python SDK.

You can install separate libraries, for example, to install the SDK to interact with Azure Storage, use the command:

    pip install azure-storage

It is recommended to install only the packages you need, but for convenience, you can install the entire set of Azure SDKs by running the following command:

    pip install azure

After installing the SDK, you get access to a variety of useful services, ranging from using the machine learning API with Azure Cognitive Services and ending with the distribution of globally distributed data using Azure Cosmos DB .

Web applications can be deployed using the Azure Container Web Application feature. Check out the video From Zero to Azure with Python and Visual Studio Code (From Azure from scratch using Python and Visual Studio Code), which provides all the necessary information for deploying Flask applications using Visual Studio Code. Also note the quick guide to deploying a Flask application using the command line.

In addition, you can run free-placed Jupyter notebooks on Azure, so a local Jupyter installation is not required. Jupyter notebooks can be opened to share them. For example, you can view a shared notebook for creating handwriting using machine learning:



Sign in to notebooks.azure.com to try out cloning and running Jupyter notebooks!

Useful materials on the topic


Mini-book "Create better applications and quickly use the data where it is needed"


Read the e-book Building Modern Big Data Applications Globally to learn how the ready-to-use, globally distributed Azure Cosmos DB database service is changing the way you manage data. Ensure data availability, consistency and protection, using industry-leading, industry-leading technologies for regulatory compliance and security. Start developing the best applications for your users based on one of five well-defined consistency models. → Download





Workshop "How to choose the right infrastructure for your workloads in Azure"


In this seminar, join the story of Microsoft Regional Director Eric Boyd, MVP Azure, about how to choose the right virtual machines, storage and networking for your applications and workloads in Azure.

Download / View

Cloud Application Architecture Guide


Use a structured approach to developing cloud applications. This 300-page e-book on cloud computing architecture discusses architecture, development, and deployment recommendations that apply regardless of the cloud platform you choose. This guide includes steps to:

  • Choosing the right style of cloud application architecture for your application or solution;
  • selection of appropriate computing and data storage technologies;
  • implementation of 10 development principles for creating a scalable, fault-tolerant and managed application;
  • following the five principles of creating high-quality software that guarantees the success of your cloud application;
  • using constructive patterns designed for the problem you are trying to solve.



Download

Also popular now: