본문 바로가기

IT/개발

vscode에서 streamlit 사용시 break point 사용하기 (launch.json, 디버깅)

반응형

sreamlit은 브라우져에서 동작하기 때문에 

streamlit run xxxxxxx.py 형태로 실행하게 됩니다.

 

브라우저 상에서 st.write()만 가지고 디버깅하기에는 어려움이 있기때문에

일반적인  디버깅 방식으로 실행하는 법을 알아보겠습니다. 

 

1. 기본 설정 

 

일단 

VSCode Python 디버거가 debugpy를 찾지 못할 경우, debugpy 모듈이 설치되지 않았거나 올바르게 설치되지 않았을 가능성이 있습니다.

 

pip install debugpy 설치

 

vscode에서 현재 프로젝트의 launch.json 수정하기

 

일반적으로 파일 디버깅을 위해서는 아래와 같이 하는데..

{

    "version": "0.2.0",

    "configurations": [    

        {

            "name": "Python 디버거: 현재 파일",

            "type": "python",

            "request": "launch",

            "program": "${file}",

            "console": "integratedTerminal",

            "justMyCode": false,

        }

    ]

}

 

2. streamlit 사용하여 디버깅하기 

 

streamlit을 사용하기 위해서는 다음과 같이 설정 해야 한다. 

 

{
    // 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: Streamlit",
            "type": "python",
            "request": "launch",            
            "module": "streamlit",
            "args": [
                "run",
                "${workspaceFolder}/실행할파이썬파일.py"
            ],
            "console": "integratedTerminal",
            "justMyCode": false
        }
    ]
}
반응형