[Python] VS Code debugger launch intermittently stops working and then does work again (Python...

Discussão em 'Python' iniciado por Stack, Maio 8, 2025.

  1. Stack

    Stack Membro Participativo

    I have a Python script which works on the command line. It also does work via VS Code's debug launch ... sometimes.

    At first I thought it was to do with a bad launch.json, in particular related to how I was inject Env variables using

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


    While the script itself uses load_dotenv() to achieve the same thing from the command line.

    But I don't think it's that, because then it started working again, after making an edit to the script and then reverting that edit - ie, no actual change except I touched the .py file.

    But "not working", I mean that this happens (see screenshot) and the script never even gets to launch.

    [​IMG]

    I don't think it's the launch config:

    {
    "version": "0.2.0",
    "configurations": [
    {
    "name": "my-script",
    "type": "debugpy",
    "request": "launch",
    "program": "${workspaceFolder}/scripts/my-script.py",
    "console": "integratedTerminal",
    "args": ["arg"],
    "python": "${workspaceFolder}/.venv/bin/python"
    //"envFile": "${workspaceFolder}/.env"
    }
    ]
    }


    Also, how the script picks up its env:

    def main():
    #dotenv_path=Path(__file__).parent.parent / ".env"
    #print(f"Loading ENV from: {dotenv_path}")
    #load_dotenv(dotenv_path)
    # This works, and so does the above, from cmd line
    # Both have worked in VS Code debugger, but something else breaks it
    load_dotenv()


    I suspect I'm doing something to fix / break it, but I can't pin down by experiment what it is.

    OS: MacBook Pro Sequoia 15.1

    Continue reading...

Compartilhe esta Página