-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Python Path and Version
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).
"python.pythonPath": "c:/python27/python.exe"
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.
{
"python.pythonPath": "/home/xxx/dev/ala/venv/bin/python"
}
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.
- Ensure none of the Python paths are configured in the settings.json file (leave them to their defaults).
- Open your terminal (command) window and activate the relevant Python environment
- Close all instances of VS Code
- Next, launch VS Code from that same terminal (command window) session
(venv) ter@minal:~$ code .
Details on configuration settings for debugging can be found here Debugging.
Configuring the version of the python executable is identical to the previous steps.
However instead of configuring the path in the settings file, you will instead be configuring the path in the launch.json file.
Once again, this is optional. If you have launched the VS Code from within the activated virtual environment, then this isn't necessary.
{
"name": "Python",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"program": "${file}",
"pythonPath": "c:/python27/python.exe",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
]
}