27

I have some shell scripts, which I would like to execute by name from code during debugging in Visual Studio Code. I need to extend $PATH environment variable to make it happened. Currently, I have following json in launch.json.

{
      "name": "Debug-Linux",
      "type": "go",
      "request": "launch",
      "mode": "debug",
      "remotePath": "",
      "port": 2345,
      "host": "127.0.0.1",
      "program": "${fileDirname}",
      "env": {
        "PATH": "$PATH:$(pwd)/../bin/" 
      },
      "showLog": true
}

Also, I've tried

"env": {
      "PATH": "${env.PATH}:$(pwd)/../bin/" 
},

But, it does not work. How can I extend $PATH environment variable in launch.json in Visual Studio Code?

Aliaksei Maniuk
  • 1,534
  • 2
  • 18
  • 30

4 Answers4

33

On Windows platform I found that Visual Studio Code seems to be case-sensitive. If the name of the variable is not spelled exactly as it is spelled on your machine, Visual Studio Code will ignore your variable from the launch.json.

For example, to properly set path environment variable when it is spelled Path, you would need to add the following to launch.json.

"env": {
      "Path": "${env:Path};${workspaceFolder}\\node_modules\\.bin" 
},

See Launch.json attributes and Variable Substitution in Visual Studio Code documentation for more information. Here what's mentioned there about the variable casing under Variable Substitution:

Note: Be sure to match the environment variable name's casing, for example ${env:Path} on Windows.

This is odd, because Windows is case-insensitive to the names of environment variables

dmytroUa
  • 471
  • 5
  • 5
  • 2
    This worked for me but vscode complains that the env property is not allowed so I changed it to this: `"environment": [{"name": "Path", "value": "${env:Path};${workspaceFolder}\\node_modules\\.bin"}],` – solarc Mar 14 '21 at 21:08
  • @solarc, can you add your comment as an answer? Your solution only works for me. – Andrey Epifantsev Jun 25 '21 at 07:57
5

According to the documentation, you should use ${env:PATH} instead of ${env.PATH}.

alextercete
  • 4,871
  • 3
  • 22
  • 36
  • Ran into something similar now in Visual Studio 2022, but actually only the undocumented `${env.PATH}` syntax worked consistently for me and it did so without being case-sensitive. The documented `${env:PATH}` worked _sometimes_, e.g. if I used `${env.PATH}` somewhere then `${env:PATH}` started working as well but otherwise it seemed to remain as is – Jurko Gospodnetić Oct 19 '22 at 18:08
2

I use this:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "gbdt debugger",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "env": {
                "PYTHONPATH": "$PYTHONPATH:/home/work/modeldebug/" 
            },
        }
    ]
}
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
1

I finally gave up on making that work, but the workaround I have done is to just paste the DOS command to set the path in the terminal before a debugging session. Something like:

set PATH=C:\Python27\Lib\site-packages\pywin32_system32;%PATH%

A little bit ugly, but at least it lets me work. I add that as a comment to my launch.json so I have it readily available. Not completely sure that would transfer cleanly for your Linux environment, but worth a try (with the appropriate syntax changes for the shell you are using, of course).

Shawn Dyer
  • 121
  • 1
  • 4