Python in Visual Studio Code – Jan 2018 Release

Dan Taylor

We’re pleased to announce the January 2018 release for the Microsoft Python extension for Visual Studio code is now available. You can the download the Microsoft Python extension for VS Code 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 VS Code documentation.

In this release we closed a total of 72 issues focusing on linting improvements, support for virtual environments, and other general improvements. Keep on reading for some of the highlights.

Improved Default Linter Rules

The default Pylint rules used in the extension have been improved to reduce noise in the editor. By default, only errors and warnings are shown that are useful for catching coding mistakes and are likely to result in runtime exceptions. We have disabled the style rules and most of the warnings, resulting in less noise in the editor when using the default settings. You can view the default ruleset definition in our Linting Python in VS Code documentation.

The default Pylint options activate all linter rules (also known as checkers), including many style warnings. This meant that previously many warnings were shown complaining about the names of variables and functions by default. While these style warnings can be useful for some code bases, they can also add a lot of unnecessary noise for others. For example, the below warning tells me that I should be using uppercase for the “urlpatterns” variable, which goes against the coding style being used in this codebase:

You can customize which rules are enabled to match the style used in your codebase by:

  • Adding a .pylintrc file in your workspace, e.g. in a specific folder with .py files or in the workspace root.
  • Modifying the python.linting.pylintArgs setting.
  • Disabling our ruleset by setting python.linting.pylintUseMinimalCheckers to false, which will enable Pylint’s own default rules.

Commands for Configuring Linting

There are new linting commands that allow you to configure some linter settings without having to manually edit configuration files. The Python: Select Linter command allows you to select your linter of choice, and the Python: Enable Linting allows you to enable and disable linting.

Selecting a linter allows you to easily switch from Pylint to Flake8 or other supported linters. Note that using this command will only enable a single linter to be run, if you want to configure multiple linters you can do so by manually editing configuration options.

Terminal Now Uses Conda and Virtual Environments

Creating a new Python terminal will now automatically activate the currently selected virtual or conda environment.

Below is a simple “hello world” flask web app. Flask is not installed globally on this machine, but it is installed in the virtual environment in the app’s current folder.

You can activate the virtual environment using the Python: Select Interpreter command:

You can create a new terminal using the Python: Create Terminal command, which will open a command window and activate the selected virtual or conda environment:

You can then run the app using python helloflask.py, and the app will run successfully because flask is available in the activated virtual environment:

In previous versions this would fail because it would run the file using the global python interpreter instead of the virtual environment’s interpreter, which does not have flask installed,.

The Python: Run File in Terminal command will also activate the selected environment before running the Python script. If for any reason you want to disable virtual environment terminal activation, set python.terminal.activateEnvironments to false.

Try it out today

Try out the Python VS Code extension today, and be sure to file an issue on our Microsoft/vscode-python GitHub page if you run into any problems.

We are continuing to improve the extension and are releasing a new version every month, so be sure to tell us what you think!

0 comments

Discussion is closed.

Feedback usabilla icon