pythonvisual-studio-code

Visual Studio Code - How to add multiple paths to python path?


I am experimenting with Visual Studio Code and so far, it seems great (light, fast, etc).

I am trying to get one of my Python apps running that uses a virtual environment, but also uses libraries that are not in the site-package of my virtual environment.

I know that in settings.json, I can specify a python.pythonPath setting, which I have done and is pointing to a virtual environment.

I also know that I can add additional paths to python.autoComplete.extraPaths, where thus far I am adding the external libraries. The problem is, when I am debugging, it's failing because it's not finding the libraries specified in python.autoComplete.extraPaths.

Is there another setting that must be used for this?


Solution

  • This worked for me:-

    in your launch.json profile entry, specify a new entry called "env", and set PYTHONPATH yourself.

    "configurations": [
        {
            "name": "Python",
            "type": "python",
            "stopOnEntry": false,
            "request": "launch",
            "pythonPath": "${config.python.pythonPath}",
            "program": "${file}",
            "cwd": "${workspaceRoot}",
            "debugOptions": [
                "WaitOnAbnormalExit",
                "WaitOnNormalExit",
                "RedirectOutput"
            ],
            "env": {
                "PYTHONPATH": "/path/a:path/b"
            }
        }
    ]