[Python] Can't edit cwd in VS Code Python Debug

Discussão em 'Python' iniciado por Stack, Abril 10, 2025.

  1. Stack

    Stack Membro Participativo

    I was trying for long time, read a lot of forums but I couldn't find the solution.

    I want to debug a function inside an Python file, the function refers to some local files with specific path, and I can't change that path . So I need to change the working directory of the debugger, I tried setting the launch.json file of the debugger in different ways and I wasn't able to achieve nothing.

    The project structure is something like this:

    Project

    • Folder 1
      • events
        • tests
          • test1.py
            • def testA
      • resources
        • resourceA
    • Folder 2
      • events
      • test . . .

    So I debug from testA function using the debug button which appears on the side of the function, which refers to resourceA, the debug refers to "project" as root, but I need it to be " Folder1 " so it access correctly to "resourceA"

    {
    "version": "0.2.0",
    "configurations": [ {
    "name": "TC debug",
    "request": "launch",
    "type": "debugpy",
    "cwd": "${workspaceFolder}/Folder1",
    "purpose":["debug-in-terminal"]
    },
    ]
    }


    {
    "version": "0.2.0",
    "configurations": [ {
    "name": "TC debug",
    "request": "launch",
    "type": "python",
    "cwd": "${workspaceFolder}/Folder1",
    "purpose":["debug-in-terminal"]
    },
    ]
    }



    {
    "version": "0.2.0",
    "configurations": [ {
    "name": "TC debug",
    "cwd": "${workspaceFolder}/Folder1",

    },
    ]
    }


    I was able to set it on IntelIJ with no problems, but I can´t do it in VS Code.

    Thanks in advance !

    Continue reading...

Compartilhe esta Página