Python in Visual Studio Code – October 2018 Release

Dan

November 8th, 2018

We are pleased to announce that the October 2018 release of the Python Extension for Visual Studio Code is now available. You can download the Python extension from the Marketplace, or install it directly from the extension gallery in Visual Studio Code. You can learn more about Python support in Visual Studio Code in the documentation.

In this release we have closed a total of 49 issues, including:

Jupyter support: import notebooks and run code cells in a Python Interactive window

Use new virtual environments without having to restart Visual Studio Code

Code completions in the debug console window

Improved completions in language server, including recognition of namedtuple, and generic types

Keep on reading to learn more!

Jupyter Support with the Python Interactive window

The extension now contains new editor-centric interactive programming capabilities built on top of Jupyter. To get started, make sure to have Jupyter installed in your environment (e.g. set your environment to Anaconda) and type #%% into a Python file to define a Cell. You will notice a “Run Cell” code lens will appear above the #%% line:

Clicking Run Cell will open the Python Interactive window to the right and run your code. You can define further cells or press Shift+Enter to run the current cell and automatically create a new one (or advance to the next cell).

Separately, if you were to open a Jupyter Notebook file (.ipynb), you will now be prompted to import the notebook as Python code:

Cells in the Jupyter Notebook will be converted to cells in a Python file by adding #%% lines. You can run the cells to view the notebook output in Visual Studio code, including plots:

Check out our blog post Data Science with Python in Visual Studio Code for a deep dive of the new capabilities!

Completions in the Debug Console

When stopped at a breakpoint and typing expressions into the debug console, you now get completions appearing:

Completions are based on variables available at runtime in the current scope.

Automatic detection of new virtual environments

The Python extension will now detect new virtual environments that are created in your workspace root while Visual Studio Code is running. You can create virtual environments from the terminal, and they are immediately available to select by clicking on the interpreter selector in the status bar, or by using the Python: Select Interpreter command.

In the screenshot above a new virtual environment named “env” was created in the terminal, and then set the active environment, as indicated by ‘env’ in the status bar. Previously you had to reload Visual Studio Code for the new environment to be available.

Other Changes and Enhancements

We have also added small enhancements and fixed issues requested by users that should improve your experience working with Python in Visual Studio Code. The full list of improvements is listed in our changelog; some notable changes include:

Add bandit to supported linters. (thanks Steven Demurjian Jr. ) ( #2775 )

to supported linters. (thanks ) ( ) Added a debugger setting to show return values of functions while stepping. ( #2463 )

) Language server completion support for namedtuple, typing.NewType, typing.TypeVar, and generic containers.

Add debugger support for pyside2. (#3235)

Be sure to download the Python extension for Visual Studio Code now to try out the above improvements. If you run into any problems, please file an issue on the Python VS Code GitHub page.