7

This question is related to this question about conda, and it is pretty straightforward:

How can I use an external environment variable inside launch.json?

For instance, selecting the python executable inside my home with $HOME, or the executable:

    {
        "name": "Python: From Home",
        "type": "python",
        "request": "launch",
        "program": "$HOME/Documents/a.py", // nor does "${HOME}" work
        "console": "internalConsole",
        "cwd": "${workspaceFolder}"
    }

or

    {
        "name": "Python: With Anaconda",
        "type": "python",
        "request": "launch",
        "program": "${file}",
        "console": "internalConsole",
        "python": "${HOME}/anaconda3/bin/python3",
        "cwd": "${workspaceFolder}"
    }

This would simplify sharing launch.json with coworkers.

senseiwa
  • 2,369
  • 3
  • 24
  • 47
  • 1
    https://code.visualstudio.com/docs/editor/variables-reference#_environment-variables – rioV8 Nov 21 '20 at 16:07
  • @rioV8 that is working, `${env:USERNAME}`, thanks! If you turn it to an answer I'll mark it as solved. – senseiwa Nov 23 '20 at 15:23

2 Answers2

6

You can use Environment variables

The syntax is like ${env:USERNAME}

rioV8
  • 24,506
  • 3
  • 32
  • 49
0

You can use the attribute "env". For example:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": true,

            // ENVINRONMENT VARIABLES
            "env": {                 
                "VAR_A": "value_a",
                "VAR_B": "value_b"

            }
        }
    ]
}
Mykola Zotko
  • 15,583
  • 3
  • 71
  • 73