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

I had the same issue, malbs answer doesn't work for me until I change semicolon to a colon,you can find it from ZhijiaCHEN's comments

"env": { "PYTHONPATH": "/path/to/a:/path/to/b" }

Alternatively, I have a hack way to achieve the same:

# at the top of project app script:
import sys
sys.path.append('/path/to/a')
sys.path.append('/path/to/b')

The Python Extension in VS Code has a setting for python.envFile which specifies the path to a file containing environment variable definitions (Refer to: https://code.visualstudio.com/docs/python/environments#_environment-variable-definitions-file). By default it is set to:

"python.envFile": "${workspaceFolder}/.env"

So to add your external libraries to the path, create a file named .env in your workspace folder and add the below line to it if you are using Windows:

PYTHONPATH="C:\path\to\a;C:\path\to\b"

The advantage of specifying the path here is that both the auto-complete as well as debugging work with this one setting itself. You may need to close and re-open VS Code for the settings to take effect.


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"
        }
    }
]