{"id":6926,"date":"2019-01-23T10:00:36","date_gmt":"2019-01-23T17:00:36","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/python\/?p=6926"},"modified":"2019-02-17T15:26:53","modified_gmt":"2019-02-17T22:26:53","slug":"python-in-visual-studio-2019-preview-2","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/python\/python-in-visual-studio-2019-preview-2\/","title":{"rendered":"Python in Visual Studio 2019 Preview 2"},"content":{"rendered":"<p>Today we are releasing <a href=\"https:\/\/visualstudio.microsoft.com\/vs\/preview\/\">Visual Studio 2019 Preview 2<\/a>, which contains new features for Python developers to improve the experience for managing Python environments and enable you to work with Python code without having to create a Python project. We\u2019ve also enabled Python support for <a href=\"https:\/\/visualstudio.microsoft.com\/services\/live-share\/\">Visual Studio Live Share<\/a>.<\/p>\n<p>We\u2019ll take a closer look at these new features in the rest of this post.<\/p>\n<h2>Creating Python Environments<\/h2>\n<p>To make it easier for you to create virtual or conda Python environments for your project, the ability to create Python environments has been moved from the Python environments window to a new <strong>Add environment<\/strong> dialog that can be opened from various parts of Visual Studio. This improves discoverability and enables new capabilities such as the ability to create conda environments on-demand and support for Open Folder described later in this post.<\/p>\n<p>For example, when opening a project that contains a requirements.txt file or environment.yml but no virtual environment or conda environment is found, you will be prompted to create an environment with a notification:<\/p>\n<p><img decoding=\"async\" class=\"size-full wp-image-6927 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/1_CreateVirtualEnv.png\" alt=\"\" width=\"1042\" height=\"358\" srcset=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/1_CreateVirtualEnv.png 1042w, https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/1_CreateVirtualEnv-300x103.png 300w, https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/1_CreateVirtualEnv-768x264.png 768w, https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/1_CreateVirtualEnv-1024x352.png 1024w\" sizes=\"(max-width: 1042px) 100vw, 1042px\" \/><\/p>\n<p>In this case clicking on \u2018Create virtual environment\u2019 will show a new Add environment dialog box, pre-configured to create a new virtual environment using the provided requirements.txt file:<\/p>\n<p><img decoding=\"async\" class=\"size-full wp-image-6928 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/2_AddEnvironment.png\" alt=\"\" width=\"1030\" height=\"679\" srcset=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/2_AddEnvironment.png 1030w, https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/2_AddEnvironment-300x198.png 300w, https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/2_AddEnvironment-768x506.png 768w, https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/2_AddEnvironment-1024x675.png 1024w\" sizes=\"(max-width: 1030px) 100vw, 1030px\" \/><\/p>\n<p>You can also use the Add environment dialog to create a conda environment, using an environment.yml file, or by specifying a list of packages to install:<\/p>\n<p><img decoding=\"async\" class=\"size-full wp-image-6930 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/3_AddCondaEnvironment.png\" alt=\"\" width=\"1027\" height=\"679\" srcset=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/3_AddCondaEnvironment.png 1027w, https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/3_AddCondaEnvironment-300x198.png 300w, https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/3_AddCondaEnvironment-768x508.png 768w, https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/3_AddCondaEnvironment-1024x677.png 1024w\" sizes=\"(max-width: 1027px) 100vw, 1027px\" \/><\/p>\n<p>The dialog also allows you to add existing virtual environments on your machine, or to install new versions of Python.<\/p>\n<p>After clicking on <strong>Create<\/strong>, you will see a progress notification in the status bar, and you can click the blue link to view progress in the Output window:<\/p>\n<p><img decoding=\"async\" class=\"size-full wp-image-6931 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/4_CreatingEnvironment.png\" alt=\"\" width=\"950\" height=\"349\" srcset=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/4_CreatingEnvironment.png 950w, https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/4_CreatingEnvironment-300x110.png 300w, https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/4_CreatingEnvironment-768x282.png 768w\" sizes=\"(max-width: 950px) 100vw, 950px\" \/><\/p>\n<p>You can continue working while the environment is being created.<\/p>\n<h2>Switching from Anaconda to Miniconda<\/h2>\n<p>Previous versions of Visual Studio allowed you to install Anaconda through the Visual Studio Installer, and while this enabled you to easily acquire Python data science packages, this resulted in large Visual Studio installation times and sometimes caused reliability issues when upgrading versions of Visual Studio. To address these problems, Anaconda has been removed in favor of the much smaller Miniconda, which is now installed as a default optional component in for the Python workload:<\/p>\n<p><img decoding=\"async\" class=\"size-full wp-image-6932 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/5_VSInstaller.png\" alt=\"\" width=\"357\" height=\"375\" srcset=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/5_VSInstaller.png 357w, https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/5_VSInstaller-286x300.png 286w\" sizes=\"(max-width: 357px) 100vw, 357px\" \/><\/p>\n<p>Miniconda allows you to create conda environments on-demand using the Add environment dialog. If you still want to continue using a full install of Anaconda, you can install Anaconda yourself and continue working with Anaconda by selecting your Anaconda install as the active Python environment. \u00a0Note that if both the Visual Studio bundled Miniconda and Anaconda are installed, we will use Miniconda to create conda environments. If you prefer to use your own conda version you can specify the path to conda.exe in Tools &gt; Options &gt; Python &gt; Conda.<\/p>\n<h2>Python Toolbar and Open Folder Support<\/h2>\n<p>In previous versions of Visual Studio we required you to create a Python project in order to work with Python code. We have added a new Python toolbar that allows you to work with Python code without having to create or open a Python project. The toolbar allows you to switch between Python environments, add new Python environments, or manage Python packages installed in the current environment:<\/p>\n<p><img decoding=\"async\" class=\"size-full wp-image-6933 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/6_PythonToolbar.png\" alt=\"\" width=\"315\" height=\"81\" srcset=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/6_PythonToolbar.png 315w, https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/6_PythonToolbar-300x77.png 300w\" sizes=\"(max-width: 315px) 100vw, 315px\" \/><\/p>\n<p>The Python toolbar will appear whenever a Python file is open and allows you to select your Python interpreter when working with files in Open Folder workspaces or Python files included in C++ or C# projects.<\/p>\n<p>In the case of Open Folder, your selection is stored in the .vs\/PythonSettings.json file so that the same environment is selected the next time you open Visual Studio. By default, the debugger will debug the currently opened Python file, and will run the script using the currently selected Python environment:<\/p>\n<p><img decoding=\"async\" class=\"size-full wp-image-6934 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/7_OpenFolder.png\" alt=\"\" width=\"798\" height=\"404\" srcset=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/7_OpenFolder.png 798w, https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/7_OpenFolder-300x152.png 300w, https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/7_OpenFolder-768x389.png 768w\" sizes=\"(max-width: 798px) 100vw, 798px\" \/><\/p>\n<p>To customize your debug settings, you can right-click a Python file and select \u201cDebug and Launch Settings\u201d:<\/p>\n<p><img decoding=\"async\" class=\"size-full wp-image-6935 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/8_DebugLaunchSettings.png\" alt=\"\" width=\"477\" height=\"274\" srcset=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/8_DebugLaunchSettings.png 477w, https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/8_DebugLaunchSettings-300x172.png 300w\" sizes=\"(max-width: 477px) 100vw, 477px\" \/><\/p>\n<p>This will generate a launch.vs.json file with Python settings which can be used to customize debug settings:<\/p>\n<p><img decoding=\"async\" class=\"size-full wp-image-6936 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/9_LaunchJson.png\" alt=\"\" width=\"400\" height=\"272\" srcset=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/9_LaunchJson.png 400w, https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/9_LaunchJson-300x204.png 300w\" sizes=\"(max-width: 400px) 100vw, 400px\" \/><\/p>\n<p>Note that in Preview 2, the editor and interactive window do not use the currently selected Python environment when using Open Folder. This functionality will be added in future previews of Visual Studio 2019.<\/p>\n<h2>Live Share Support for Python<\/h2>\n<p>In this release you can now use <a href=\"https:\/\/visualstudio.microsoft.com\/services\/live-share\/\">Visual Studio Live Share<\/a> with Python files. Previously, you could only use Live Share with Python by hosting a session with Visual Studio Code. You can initiate a Live Share session by clicking the Live Share button on the upper right corner of Visual Studio:<\/p>\n<p><img decoding=\"async\" class=\"size-full wp-image-6937 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/10_StartCollaborationSession.png\" alt=\"\" width=\"358\" height=\"350\" srcset=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/10_StartCollaborationSession.png 358w, https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/10_StartCollaborationSession-300x293.png 300w\" sizes=\"(max-width: 358px) 100vw, 358px\" \/><\/p>\n<p>Users who join your live share session will be able to see your Python files, see IntelliSense from your selected Python environment, and collaboratively debug through Python code:<\/p>\n<p><img decoding=\"async\" class=\"size-full wp-image-6938 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/11_JoinCollaborationSession.png\" alt=\"\" width=\"796\" height=\"384\" srcset=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/11_JoinCollaborationSession.png 796w, https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/11_JoinCollaborationSession-300x145.png 300w, https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/02\/11_JoinCollaborationSession-768x370.png 768w\" sizes=\"(max-width: 796px) 100vw, 796px\" \/><\/p>\n<h2>Try it out!<\/h2>\n<p>Be sure to download the <a href=\"https:\/\/visualstudio.microsoft.com\/vs\/preview\/\">Visual Studio 2019 Preview 2<\/a>, <a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/python\/installing-python-support-in-visual-studio?view=vs-2017\">install the Python Workload<\/a>, and give feedback on <a href=\"https:\/\/developercommunity.visualstudio.com\/spaces\/8\/index.html\">Visual Studio Developer Community<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today we are releasing Visual Studio 2019 Preview 2, which contains new features for Python developers to improve the experience for managing Python environments and enable you to work with Python code without having to create a Python project. We\u2019ve also enabled Python support for Visual Studio Live Share. In this post we\u2019ll take a closer look at these new features.<\/p>\n","protected":false},"author":883,"featured_media":6930,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-6926","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-visual-studio"],"acf":[],"blog_post_summary":"<p>Today we are releasing Visual Studio 2019 Preview 2, which contains new features for Python developers to improve the experience for managing Python environments and enable you to work with Python code without having to create a Python project. We\u2019ve also enabled Python support for Visual Studio Live Share. In this post we\u2019ll take a closer look at these new features.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/posts\/6926","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/users\/883"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/comments?post=6926"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/posts\/6926\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/media\/6930"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/media?parent=6926"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/categories?post=6926"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/tags?post=6926"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}