How to configure VS Code launch.json to debug a Streamlit app with a conda environment?

How to configure VS Code launch.json to debug a Streamlit app with a conda environment?

To debug a python project with a specific conda env in VS code, I normally use this launch.json

{
    "version": "0.2.0",
    "configurations": [

        {
            "name": "Python Debugger: Current File",
            "type": "debugpy",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "args": [
                "--video_path","./../test_real.mp4",
                
            ],
            "python": "/home/<username>/miniconda3/envs/myconda_env/bin/python" // Update to the Python binary for gradtts environment
        }
    ]
}

Now I want to debug a streamlit app in the VS code. The command to launch a streamlit app is $ streamlit run main.py. How to modify the launch.json to achieve this task in VS code?

Answer

To debug a streamlit app in VS code, the launch.json can be modified like this:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug Streamlit App",
            "type": "debugpy",
            "request": "launch",
            "program": "-m",
            "args": [
                "streamlit",
                "run",
                "main.py"
            ],
            "python": "/home/<username>/miniconda3/envs/myconda_env/bin/python",
            "console": "integratedTerminal",
            "justMyCode": false,
            "env": {
                "PYTHONUNBUFFERED": "1"
            },
            "cwd": "${workspaceFolder}"
        }
    ]
}

Enjoyed this question?

Check out more content on our blog or follow us on social media.

Browse more questions