| Order | 5 |
|---|---|
| Area | python |
| TOCTitle | Environments |
| ContentId | 8fe4ca8b-fc70-4216-86c7-2c11b6c14cc6 |
| PageTitle | Configuring Python Environments in Visual Studio Code |
| DateApproved | 11/10/2017 |
| MetaDescription | Configuring Python Environments in Visual Studio Code |
| MetaSocialImage | tutorial_social.png |
By default, the Python extension relies on the first Python interpreter it finds in the path. The extension uses that interpreter for IntelliSense, auto-completions, linting, formatting, and any other language-related feature other than debugging.
To select a specific interpreter, select the Python: Select Workspace Interpreter command (on the Command Palette):
This command automatically looks for and displays a list of available Python interpreters.
Selecting an interpreter from the list configures the settings.json file accordingly. The statusbar shows the current interpreter and when selected brings up a list of available interpreters. The statusbar also reflects when no interpreter is selected.
The extension looks for interpreters in the following locations:
- Standard paths such as
/usr/local/bin,/usr/sbin,/sbin,c:\\python27,c:\\python36, etc. - Virtual environments located under the workspace (project) folder
- Conda environments
If the interpreter you want to use is not located automatically, you can set the path to it directly in settings.json:
-
Select the File > Preferences > Settings command.
-
Create or modify an entry for
python.pythonPathwith the full path to the Python executable. For example:Windows:
"python.pythonPath": "c:/python36/python.exe"
Mac/Linux:
"python.pythonPath": "/home/python36/python"
An environment variable can be used in the path setting using the syntax ${env.VARIABLE}. For example:
{
"python.pythonPath": "${env.PYTHONPATH}/venv/bin/python"
}To use a Python interpreter that's installed in a virtual environment:
-
Edit the
python.pythonPathsetting to point to the virtual environment. For example:Windows:
{ "python.pythonPath": "c:/dev/ala/venv/Scripts/python.exe" }Mac/Linux:
{ "python.pythonPath": "/home/xxx/dev/ala/venv/bin/python" } -
Configure the same
python.pythonPathvariable inlaunch.json. -
Ensure that the the libraries and modules you plan on using for linting are installed within the virtual environment.
-
Restart VS Code.
By default, the debugger uses the same python.pythonPath setting as for other features of VS Code. Specifically, the value for pythonPath in the debugger settings simply refers to the main interpreter setting as follows:
{
"name": "Python",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"program": "${file}",
"pythonPath": "${config.python.pythonPath}",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
]
}To use a different interpreter for debugging, specify its path directly in the pythonPath setting.
Note: The debugger settings don't support relative paths, including when relying on the main
python.pythonPathsetting. To work around this, use an environment variable, or create a variable such as${workspaceRoot}that resolves to your project folder, then use that variable in the path, as in"python.pythonPath": "${workspaceRoot}/venv/bin/python".
For information on general debugging configuration, see Debugging.
- Editing code - Learn about autocomplete, IntelliSense, formatting, and refactoring for Python.
- Debugging - Learn to debug Python both locally and remotely.
- Unit testing - Configure unit test environments and discover, run, and debug tests.
- Settings reference - Explore the full range of Python-related settings in VS Code.


