We are pleased to announce that the September 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 45 issues, including:
- Automatic activation of environments in the terminal.
- Support for Python environments in split terminals.
- Debugger support for the breakpoint() built-in.
- Improved Go To Definition and find all references in the Python Language Server.
- Reduced CPU and Memory consumption in the Python Language Server.
Automatic Activation of Environments in the Terminal
When you create a new terminal, the extension now automatically activates the selected Python pipenv, conda, pyenv, or virtual environment so that you can run python and pip/conda commands. In the below screenshot we have the 'env' virtual environment selected (as indicated in the status bar) and then created a new terminal using Terminal > New Terminal (Ctrl+Shift+`), and the virtual environment is activated automatically when the terminal is created:
You no longer need to use the Python: Create Terminal command to create an activated Python terminal (terminals with a Python environment activated).
It is also possible to use activated Python terminals in split terminal mode. The extension uses the selected Python environment at the time the terminal is created, so if you want to have terminals with two different environments activated, you can change your environment and create a new terminal.
The screenshot below shows two different Python environments side-by-side terminals, resulting from clicking on the Python interpreter in the status bar and changing it to 'otherenv' and then clicking the split icon in the terminal:
The extension now shows the name of the environment in the status bar, making it easy to determine which environment is active if you have multiple environments in your workspace.
If you are not seeing your environment selected, you may need to first open a Python file to load the Python extension, or if the terminal was created before an environment was selected you may need to create a new terminal. Note that global interpreters do not get activated in terminals, so you'll need to run those using e.g. python3 (Linux/macOS) or py -3 (Windows).
The debugger now supports the breakpoint() built-in in Python 3.7. If you are on Python 3.7 you can add a breakpoint() call, and the debugger will automatically stop on that line when it is hit (you must already be running under the debugger for this functionality; it will not launch the debugger automatically for you).
In the below example the debugger stops on a breakpoint() call inside of a Django view:
The extension now displays auto-complete for expressions typed into the debug console, after hitting the above breakpoint we can get auto-complete for the request object in the debug-console:
Improvements to Language Server Preview
We've made improvements to the preview of the Microsoft Python Language Server, first released in the July release of the Python extension. In this release we have fixed cases where runaway CPU and Memory consumption caused by storing too many symbols, particularly when using the outline view, and fixed various issues where Find All References and Go to Definition weren’t working as expected.
Rename symbol is also available with the language server without installing rope, to rename a symbol right->click and select Rename Symbol (F2).
As a reminder, to opt-in to the language server, change the python.jediEnabled setting to false in File > Preferences > User Settings. We are working towards making the language server the default in future releases.
Various Fixes and Enhancements
This release includes a number of other fixes an enhancements to the Python extension, the ptvsd 4.1.3 release of the debugger, and the Microsoft Python Language Server 2018.9.0 release. The full list is improvements is available in our changelog, some notable ones include:
- Files on network drives can now be debugged. #786, #817
- Support for code completion in the debug console window. (#1076)
- Display notification when attempting to debug without selecting a python interpreter. (#2494)
- Add support for activation of
pyenvenvironments in the Terminal. (#1526)
- Search for default known paths for conda environments on windows. (#2794)
- Use full path to activate command in conda environments on windows when python.condaPath is set. (#2753)