Skip to content

Python Path and Version

Don Jayamanne edited this page Jun 16, 2016 · 18 revisions

Python Path and Version

At the moment shebang is supported only on Windows. Until then the version of python used for standard editor functions (intellisense, linting, formatting, etc.) and debugging needs to be configured individually.

###Paths All samples provided here are for windows.
However Mac/Linux paths are also supported.

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 different version is to be used, this can be configured in one of two ways:

  • Configure the path to the python interpreter in the User Settings file (settings.json) as follows.
    Ensure to specify the fully qualified name of the python executable.
"python.pythonPath": "c:/python27/python.exe"
  • Configure the path to the python interpreter in the Workspace Settings file (settings.json) as follows.
    Ensure to specify the fully qualified name of the python executable.
"python.pythonPath": "c:/python27/python.exe"

Virtual Environments

If using a Virtual Environment, there are two approaches to to getting this extension working in a particular Virtual Environment. If not using any virtual environment, then proceed to Option 2.

Option 1: 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. Next, launch VS Code from that terminal (command window) session.
(venv) ter@minal:~$ code project_folder/

Option 2: Ensure the path to the python interpreter is set in python.pythonPath as defined above.

For code Intellisense, Auto complete and the like to work, you will also need to configure the python.autoComplete.extraPaths, on top of the python.pythonPath as follows:

{
    "python.pythonPath": "/home/xxx/dev/ala/venv/bin/python",
    "python.autoComplete.extraPaths": [
        "/home/xxx/dev/ala/venv/lib/python2.7",
        "/home/xxx/dev/ala/venv/lib/python2.7/site-packages"
     ]
}

Unfortunately the python.pythonPath is not used by the Linters when dealing with a Virtual Environment. For the moment, you will need to ensure the fully qualified path to the linters are provided. This will be fixed in a future release #148.

Python Version used for debugging

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

If using a Virtual Environment, there are two approaches to to getting this extension working in a particular Virtual Environment. If not using any virtual environment, then proceed to Option 2.

###Option 1: See Option 1 in configuring Virtual Environment.

###Option 2: Configure the launch.json file. Simply provide the fully qualified path to the python executable in the "python" setting within the configuration settings in the launch.json file as follows:

{
    "name": "Python",
    "type": "python",
    "request": "launch",
    "stopOnEntry": true,
    "program": "${file}",
    "pythonPath": "c:/python27/python.exe",
    "debugOptions": [
        "WaitOnAbnormalExit",
        "WaitOnNormalExit",
        "RedirectOutput"
    ]
}
Clone this wiki locally