Vscode Python

 

By default the extension uses the Python interpreter available in the current path. You could always change this by specifying the path to the interpreter in the user or worksapce settings.

Selecting an interpreter

First and foremost - the Python plugin for VS Code. Out of the box, there is no support for Python in VS Code, but when you open a Python file, VS Code will immediately suggest this plugin. It adds all the necessary features: Syntax highlighting for Python files.

Configuring the extension to use a particular interpreter is now easy.All you now need to do is make use of the command Select Workspace Interpreter from the command palette and select an interpreter from the list.If the interpreter you are looking for isn’t listed here, then please proceed to the next section and enter it manually.

  1. I'm using the newest version of VSCODE and Python 3.6 (64bit) on Windows 10. I have the 'Python' extension installed (the one made by Microsoft). Every time I try to run a simple program e.g: pr.
  2. Nov 08, 2018 I love VSCode, and while this is a nice step, it is still sorely missing a first-class REPL experience when it comes to Python. It would be great if it could have a mix of features from Spyder (All code executed in a live iPython console that is persistent and can be interacted with at any point, ability to use cell magics to eval blocks of code in the console, a good variable viewer for.
  3. In this video I will show you how to setup VSCode to write Python code with some helpful extensions that include features like managing environments, intelli.
  4. I love VSCode, and while this is a nice step, it is still sorely missing a first-class REPL experience when it comes to Python. It would be great if it could have a mix of features from Spyder (All code executed in a live iPython console that is persistent and can be interacted with at any point, ability to use cell magics to eval blocks of code in the console, a good variable viewer for.
Vscode

Manual Configuration

Python Version used for Intellisense, Autocomplete, Linting, Formatting, etc
The same python interpreter is used for intellisense, autocomplete, linting, formatting, etc. (everything other than debugging). The standard interpreter used is the first “python” interpreter encountered in the current path.

If a specific version is to be used, then configure the path to the python interpreter in the User or Workspace Settings file (settings.json) as follows.
Ensure to specify the fully qualified name of the python executable (Mac and Linux supported).

Virtual Environments

There are two approaches to to getting this extension working in a particular Virtual Environment.

Option 1: Ensure the path to the python interpreter is set in python.pythonPath as defined previously.

Note: Do remember to configure the pythonPath in launch.json as well.

Python visual studio

Finally, restart VS Code, necessary for intellisense to work (future release will not require a restart)
Ensure the libraries/modules you plan on using for linting are also installed within this virtual environment.

Option 2: Activate the Virtual Environment from your Terminal/Command Window and then launch VS Code.

  1. Ensure none of the Python paths are configured in the settings.json file (leave them to their defaults).
  2. Open your terminal (command) window and activate the relevant Python environment
  3. Close all instances of VS Code
  4. Next, launch VS Code from that same terminal (command window) session

Python Version used for debugging

Visual studio code python autocomplete

Details on configuration settings for debugging can be found here Debugging.

Configuring the version of the python executable is no longer necessary.
Provided the setting python.pythonPath in settings.json (see above) has been configured correctly, the debugger will use this same setting.

This is made possible by setting the value of the pythonPath setting to ${config.python.pythonPath}. I.e. the debugger merely references the pythonPath setting from the settings.json file.

Python

Relative Paths to Python Interpreter

Unfortunately use of relative paths when configuring the interpreter in settings.json will not work with the debugger. Hence the solution is to provide the fully qualified path.This could be achieved with the use of simple variables such as the following:
Where ${workspaceRoot} resolves to the current work space (project) directory.

Environment Variables

Python

Vscode Python Linter

Similar to the use of ${workspaceRoot}, environment variables could be used in configuring the path to the python interpreter.Where ${env.PYTHONPATH} resolves to the value of the environment variable xyz.

Vscode Python Setup

This extension provides an integration of PyDev (http://www.pydev.org) in VSCode, enabling users to leverage the features of one of the leading Python IDEs inside VSCode.

Note: this extension provides a 30-day trial after installation and must be purchased for continued use.

Check http://www.pydev.org/vscode for more details!

Features currently available

  • Code-completion

    • Fast
    • Context sensitive
    • Common tokens
    • Context insensitive with auto import
  • Code formatter

    • Fast
    • Format ranges
    • Format on type
  • Code analysis

    • Real time
  • Go to definition

  • Symbols for Workspace

  • Symbols for open editor

  • Find references

  • Quick fix for undefined variables (adds missing import)

  • Navigate to previous or next class or method (Ctrl+Shift+Up, Ctrl+Shift+Down)

Requirements

Java 8 must be installed -- python.pydev.java.home may be used to specify its location if it's not found. See http://www.pydev.org/vscode for instructions and other settings.

Changelog

See: http://www.pydev.org/vscode/history.html

License

  • PyDev VSCode extension: Commercial (http://www.pydev.org/vscode/license.html)

Other bundled components:

  • PyDev: EPL (https://www.eclipse.org/org/documents/epl-v10.php)
  • LSP4J: EPL (https://www.eclipse.org/org/documents/epl-v10.php)
  • Eclipse core libraries: EPL (https://www.eclipse.org/org/documents/epl-v10.php)