# Vs code debug

**URL:** <https://discuss.streamlit.io/t/vs-code-debug/520>\
**Category:** Using Streamlit\
**Created:** [October 16, 2019, 12:13pm UTC](https://discuss.streamlit.io/t/vs-code-debug/520 "2019-10-16T12:13:42Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nelson\_Silva](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/nelson_silva/32/329_2.png) [@Nelson\_Silva](https://discuss.streamlit.io/u/Nelson_Silva)\
**Post date:** [October 16, 2019, 12:13pm UTC](https://discuss.streamlit.io/t/vs-code-debug/520/1 "2019-10-16T12:13:42Z")

</div>

How to debug a [streamlit.io](http://streamlit.io) python app using VS Code?

Thank you!

---

<div class="post-metadata">

**Author:** ![Marc](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/marc/32/602_2.png) [@Marc](https://discuss.streamlit.io/u/Marc)\
**Post date:** [October 16, 2019, 6:38pm UTC](https://discuss.streamlit.io/t/vs-code-debug/520/2 "2019-10-16T18:38:39Z")

</div>

Hi @Nelson_Silva

The poor mans version is to just set a `breakpoint()` in the code.

You can see an example below where i’ve set the ‘breakpoint()’ and can inspect the selection in the terminal below.

I don’t know how to integrate it with VS Code though. I never use that because I find it slow 🙂

 ![image](https://global.discourse-cdn.com/streamlit/original/1X/299c4eb635a9546a9890c74d43497a672bcc1bae.png)

---

<div class="post-metadata">

**Author:** ![Nelson\_Silva](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/nelson_silva/32/329_2.png) [@Nelson\_Silva](https://discuss.streamlit.io/u/Nelson_Silva)\
**Post date:** [October 16, 2019, 8:05pm UTC](https://discuss.streamlit.io/t/vs-code-debug/520/3 "2019-10-16T20:05:17Z")

</div>

Thank you for the previous answer.

After some reading, here is the description on how to debug Streamlit apps using VS CODE:

In your streamlit/Python code add:

import ptvsd

-\> 5678 is the default attach port in the VS Code debug configurations

print(“Waiting for debugger attach”)

ptvsd.enable\_attach(address=(‘localhost’, 5678), redirect\_output=True)

ptvsd.wait\_for\_attach()

-\> use: breakpoint(), to set a manual breakpoint using code, or just enable a breakpoint using the mouse on the code line (as usual)

-\> Next run you Streamlit as usual: streamlit run test.py  
-\> Next, you just need to press the play button on VS CODE, and then select the Remote Attach: debug PTVSD option…

#Done!

---

<div class="post-metadata">

**Author:** ![Marc](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/marc/32/602_2.png) [@Marc](https://discuss.streamlit.io/u/Marc)\
**Post date:** [November 9, 2019, 5:53am UTC](https://discuss.streamlit.io/t/vs-code-debug/520/4 "2019-11-09T05:53:32Z")

</div>

Hi @Nelson_Silva

Your description got me started writing some suggestions on how to use VS Code for developing Streamlit applications. See [https://awesome-streamlit.readthedocs.io/en/latest/vscode.html](https://awesome-streamlit.readthedocs.io/en/latest/vscode.html)

 ![image](https://global.discourse-cdn.com/streamlit/original/1X/7a508e8bdb04304d568e8312a061236fb94e51c1.png)

Thanks.

---

<div class="post-metadata">

**Author:** ![Pablo\_Alfaro](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/pablo_alfaro/32/4869_2.png) [@Pablo\_Alfaro](https://discuss.streamlit.io/u/Pablo_Alfaro)\
**Post date:** [December 29, 2020, 11:29pm UTC](https://discuss.streamlit.io/t/vs-code-debug/520/5 "2020-12-29T23:29:38Z")

</div>

Hey @Marc, @Nelson_Silva,  
Thank you for this very useful discussion and article.  
I tried applying the solution for the integrated debugger on it only to find ptvsd is no longer supported: [https://github.com/microsoft/ptvsd/issues/1682#issuecomment-732793614](https://github.com/microsoft/ptvsd/issues/1682#issuecomment-732793614)

I did manage to get it to work by using debugpy in a similar way to what they do here [https://dockerquestions.com/2020/09/22/debugging-python-in-docker-container-using-debugpy-and-vs-code-results-in-timeout-connection-refused/:](https://dockerquestions.com/2020/09/22/debugging-python-in-docker-container-using-debugpy-and-vs-code-results-in-timeout-connection-refused/:)

I changed the code in app\_debug\_vscode.py to use debugpy like this:

```
"""Use this module for development with VS Code and the integrated debugger"""
import debugpy
import streamlit as st
import app

# pylint: disable=invalid-name
markdown = st.markdown(
"""
## Ready to attach the VS Code Debugger!
![Python: Remote Attach](https://awesome-streamlit.readthedocs.io/en/latest/_images/vscode_python_remote_attach.png)
for more info see the [VS Code section at awesome-streamlit.readthedocs.io]
(https://awesome-streamlit.readthedocs.io/en/latest/vscode.html#integrated-debugging)
"""
)

if not debugpy.is_client_connected():
    debugpy.listen(5679)
    debugpy.wait_for_client()

markdown.empty()

app.main()

```

Also I had to change the port to 5679 (here and on launch.json) because 5678 refused to work saying it was already in use. Maybe the other debugger was trying to run there? Figure with a fresh restart 5678 should work.

Again, thanks for your help!

---

<div class="post-metadata">

**Author:** ![shriaviator](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/shriaviator/32/5855_2.png) [@shriaviator](https://discuss.streamlit.io/u/shriaviator)\
**Post date:** [April 16, 2021, 1:43pm UTC](https://discuss.streamlit.io/t/vs-code-debug/520/6 "2021-04-16T13:43:55Z")

</div>

@Marc  
[Can u please update the article awesome-streamlit](https://awesome-streamlit.readthedocs.io/en/latest/vscode.html)  
It still works as described in the article in vscode /win 10/ py3.8 today  
Any updated comments would be highly useful

---

<div class="post-metadata">

**Author:** ![bjornba](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/bjornba/32/7622_2.png) [@bjornba](https://discuss.streamlit.io/u/bjornba)\
**Post date:** [May 5, 2021, 11:20am UTC](https://discuss.streamlit.io/t/vs-code-debug/520/7 "2021-05-05T11:20:34Z")

</div>

For anyone stumbling over this thread. My launch.json below. Put a breakpoint inside run.py and hit F5. Simple solution that works for me running on wsl.

```auto
{
"version": "0.1.0",
"configurations": [
    {
        "name": "debug streamlit",
        "type": "python",
        "request": "launch",
        "program": "/path/to/streamlit", // /home/xx/tmp/venv/bin/streamlit",
        "args": [
            "run",
            "run.py"
        ]
    }
]
}

```

---

<div class="post-metadata">

**Author:** ![OmarMAmin](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/omarmamin/32/9131_2.png) [@OmarMAmin](https://discuss.streamlit.io/u/OmarMAmin)\
**Post date:** [August 29, 2021, 7:34pm UTC](https://discuss.streamlit.io/t/vs-code-debug/520/8 "2021-08-29T19:34:47Z")

</div>

Thanks @bjornba, You saved me a lot of time (Y)

---

<div class="post-metadata">

**Author:** ![moerv9](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/moerv9/32/14711_2.png) [@moerv9](https://discuss.streamlit.io/u/moerv9)\
**Post date:** [July 27, 2022, 11:44am UTC](https://discuss.streamlit.io/t/vs-code-debug/520/9 "2022-07-27T11:44:05Z")

</div>

Dude brilliant! That was great advice!

Here are all steps you need to do in Vscode:

1. click on the _run and debug_ item in the primary sidebar on the left
2. Click `create launch.json`
3. in the launch.json file in the .vscode folder add the code from @bjornba
4. edit the code for your settings:  
For anaconda under Mac you will find the `path/to/streamlit` in `"/Users/[username]/opt/anaconda3/envs/[envname]/bin/streamlit"`

and under args change the run.py to your filename.

It worked perfectly! Big thanks!

---

<div class="post-metadata">

**Author:** ![jfthuong](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/jfthuong/32/65434_2.png) [@jfthuong](https://discuss.streamlit.io/u/jfthuong)\
**Post date:** [October 18, 2022, 8:56am UTC](https://discuss.streamlit.io/t/vs-code-debug/520/10 "2022-10-18T08:56:53Z")

</div>

Nice!!

An alternate configuration I have found with Google:

> **[Debug streamlit app in vscode](https://slashgordon.github.io/post/debug_streamlit_in_vscode/)**
>
> Today I want to share my vscode launch configuration for streamlit live debugging.

```json
{
   "version": "0.2.0",
   "configurations": [{
        "name": "Python: Streamlit",
        "type": "python",
        "request": "launch",
        "module": "streamlit",
        "env": {
            "STREAMLIT_APP": "app.py",
            "STREAMLIT_ENV": "development",
            "AWS_PROFILE": "mega_root",
            "PYTHONPATH": "${workspaceRoot}/src",
        },
        "args": [
            "run",
            "/Users/projects/streamlit/app.py"
        ],
        "jinja": true
    }
   ]
}

```

---

<div class="post-metadata">

**Author:** ![asehmi](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/asehmi/32/1771_2.png) [@asehmi](https://discuss.streamlit.io/u/asehmi)\
**Post date:** [October 20, 2022, 1:19am UTC](https://discuss.streamlit.io/t/vs-code-debug/520/11 "2022-10-20T01:19:55Z")

</div>

Hi,

It’s good practice to use a remote debugger for server apps. I’ve built a little wrapper for `debugpy` (`pip install debugpy`) which you can use. The code is available in [my gist here](https://gist.github.com/asehmi/aafacaef2b56332c341794fe18e01f9d). Full instructions included on creating the `launch.json` file and adding two lines of code to your top level Streamlit app.

Benefits: (a) You can use this approach to debug locally and into apps running in local or remote dockers. (b) You can launch the debugger anytime after your Streamlit app has started, and (c) You can control the `wait_for_client` flag to pause and wait (`=True`) for you to start the debugger. The debugger wrapper is enabled by making `flag=True`.

I never build any apps without this.

HTH,  
Arvindra

---

<div class="post-metadata">

**Author:** ![J4c0b1](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/j4c0b1/32/28742_2.png) [@J4c0b1](https://discuss.streamlit.io/u/J4c0b1)\
**Post date:** [July 18, 2023, 1:28pm UTC](https://discuss.streamlit.io/t/vs-code-debug/520/12 "2023-07-18T13:28:35Z")

</div>

Use this for any app you may have.

```auto
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": true
        },
        {
            "name": "Python: Streamlit",
            "type": "python",
            "request": "launch",
            "module": "streamlit",
            "env": {
                // any .env variables you may have
                "STREAMLIT_APP": "${file}",
                "STREAMLIT_ENV": "development",
            },
            "args": [
                "run",
                "${file}"
            ],
            "jinja": true,
            "justMyCode": true
        }
    ]
}

```

---

<div class="post-metadata">

**Author:** ![JuanFMontesinos](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/juanfmontesinos/32/33610_2.png) [@JuanFMontesinos](https://discuss.streamlit.io/u/JuanFMontesinos)\
**Post date:** [October 24, 2023, 10:38am UTC](https://discuss.streamlit.io/t/vs-code-debug/520/13 "2023-10-24T10:38:58Z")

</div>

You are overcomplicating this.  
It’s a matter of calling python3 -m streamlit run file.py. that can be done by for any VS code file. It’s agnostic to venv as well and works with remote kernels.

```auto
        {
            "name": "streamlit debug",
            "type": "python",
            "request": "launch",
            "module": "streamlit",
            "args": ["run", "${file}"],
            "justMyCode": true,
        }

```

This will in practice call  
`streamlit run full_path_to_file `

---

<div class="post-metadata">

**Author:** ![dmanning23](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/dmanning23/32/34132_2.png) [@dmanning23](https://discuss.streamlit.io/u/dmanning23)\
**Post date:** [November 6, 2023, 5:36am UTC](https://discuss.streamlit.io/t/vs-code-debug/520/14 "2023-11-06T05:36:35Z")

</div>

Worked like a charm, ty!

---

<div class="post-metadata">

**Author:** ![netadept](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/netadept/32/35013_2.png) [@netadept](https://discuss.streamlit.io/u/netadept)\
**Post date:** [November 26, 2023, 11:41pm UTC](https://discuss.streamlit.io/t/vs-code-debug/520/15 "2023-11-26T23:41:57Z")

</div>

Wow that was so much easier! It’s so obvious too (but not so obvious that I didn’t go down the other rabbit holes first). Thank you, I appreciate you.

---

<div class="post-metadata">

**Author:** ![JW\_Soh07](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/jw_soh07/32/28685_2.png) [@JW\_Soh07](https://discuss.streamlit.io/u/JW_Soh07)\
**Post date:** [April 18, 2024, 2:41am UTC](https://discuss.streamlit.io/t/vs-code-debug/520/16 "2024-04-18T02:41:54Z")

</div>

quality advice! thank you!

---

<div class="post-metadata">

**Author:** ![Condemor](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/condemor/32/5597_2.png) [@Condemor](https://discuss.streamlit.io/u/Condemor)\
**Post date:** [April 22, 2024, 1:27am UTC](https://discuss.streamlit.io/t/vs-code-debug/520/17 "2024-04-22T01:27:02Z")

</div>

Great tip. Adding that “program”: might need to be adjusted in case you are using a virtual environment.

---

<div class="post-metadata">

**Author:** ![janaka](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/janaka/32/28810_2.png) [@janaka](https://discuss.streamlit.io/u/janaka)\
**Post date:** [April 26, 2024, 3:23pm UTC](https://discuss.streamlit.io/t/vs-code-debug/520/18 "2024-04-26T15:23:15Z")

</div>

Hey all, any tips on how to get this working with a poe task, specifically the one below?

```auto
[tool.poe.tasks.run-otel-infisical]

cmd = "infisical run --env=dev -- opentelemetry-instrument --logs_exporter none streamlit run web/index.py --server.port $port --browser.gatherUsageStats false --server.runOnSave true --server.fileWatcherType auto"

args = [{ name = "port", default = 8501, type = "integer" }]

env = { WATCHDOG_LOG_LEVEL = "ERROR", PYTHONPATH = "${PWD}/web/:${PWD}/source/:${PWD}/../docq-extensions/source/" }

```

---

<div class="post-metadata">

**Author:** ![lucifer-ved](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/lucifer-ved/32/43709_2.png) [@lucifer-ved](https://discuss.streamlit.io/u/lucifer-ved)\
**Post date:** [May 28, 2024, 12:59pm UTC](https://discuss.streamlit.io/t/vs-code-debug/520/19 "2024-05-28T12:59:11Z")

</div>

Thanks a ton for this !

---

<div class="post-metadata">

**Author:** ![Alex4](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/alex4/32/44700_2.png) [@Alex4](https://discuss.streamlit.io/u/Alex4)\
**Post date:** [June 11, 2024, 6:17pm UTC](https://discuss.streamlit.io/t/vs-code-debug/520/21 "2024-06-11T18:17:54Z")

</div>

Hi I just find this thread, but even I config my launch.json like below, it is not work (breaking point in my program not stopping)

```auto
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": true
        },
        {
            "name": "Streamlit",
            "type": "python",
            "request": "launch",
            "module": "streamlit",
            "console": "integratedTerminal",
            "justMyCode": true,
            "jinja": true,
            "args": [
                "run",
                "${file}",
            ]
        }
    ]
}

```

[Next page](https://discuss.streamlit.io/t/vs-code-debug/520.md?page=2)
