update: 2020-05-03
update: 2017-11-15
Microsoft 가 기존의 Don Jayamanne 의 extension 에 대한 지원을 이어받아서 하기로 했다.Visual Studio Code 에서 python debugger 사용하기
여기서는 windows 에서 사용하는 방법을 이야기 한다. ref. 3 에 따르면 아직 linux 에서virtualenv 를 사용할 수는 없다고 하는 듯 하다. windows 에서는 pythonPath 를 virtualenv 의 exe 로 설정해서 사용할 수 있다. 일단 좀 더 자세히 알아보자.절차
- Visual Studio Code 설치
- python plugin 설치
- settings.json 의 pythonPath 설정
- File > Open Folder > python project folder 선택
- launch.json 수정
- debugger 로 실행 : F5
- intellisense 를 위한 추가 path 설정
python plugin 설치
settings.json 의 pythonPath 설정
python interprester 선택(update : 2017-11-15)
이 명령어를 사용하면 workspace setting 에 pythonPath에 대한 설정을 자동으로 해준다.- python interprester 선택:
- Ctrl+Shift+P -> Python: Select Interpreter
- 이것을 제대로 설정 해야 제대로 함수등에 대한 navigation 이 된다.
File > Open Folder > python project folder 선택
python project 의 root 을 선택하면 된다.launch.js 설정
debug 하길 원하는 .py 를 열고 여기서 F5 를 누르자. launch.js 가 설정되어 있지 않다면, 자동으로 .vscode/launch.json 이 생성되고, 창에 보여 준다.여기서 일반적인 console program 은 Python Console App 부분에 설정 해 주면 된다.
virtualenv 를 사용하는 경우에는 pythonPath 만 추가로 설정해 주면 된다.[ref. 3] 만약 virtualenv 인 경우 virtualenv 의 python.exe 경로를 설정 해 주면 된다.
itellisense(ctrl + space) 를 누르면 어떤 값이 가능한 지 알 수 있다.
launch.js
{
"version": "0.2.0",
"configurations": [
{
"name": "Python",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"program": "${file}",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
]
},
{
"name": "Python Console App",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"program": "${file}",
"externalConsole": false,
"pythonPath": "d:/envs/eedn/Scripts/python.exe",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
]
},
{
"name": "Django",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"program": "${workspaceRoot}/manage.py",
"args": [
"runserver",
"--noreload"
],
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput",
"DjangoDebugging"
]
}
]
}
debugger 로 python program 실행
이제 다시 원하는 .py 를 열고 원하는 breakpoint 를 설정하고 F5 를 누르자. 그러면 debugger 가 실행하게 된다.intellisense 를 위한 path 설정
intellisense (자동완성) 를 위해 추가적으로 library 에 대한 path 를 설정 해 줄 수 있다. 이부분은 settings.json 에 추가해 주면 된다. settings.json 은 command pallete(ctrl+alt+p) 에서 setting 을 쳐서- Preferences : Open Workspace Settings
"python.autoComplete.extraPaths": [
"C:/virtualenv/min/Lib",
"C:/virtualenv/min/Lib/site-packages",
"C:/Program Files (x86)/Google/google_appengine/lib" ],
"files.exclude": {
"*/**.pyc": true
}
Django Project 설정
virtualenv 인 경우에 lauch.json 에서 pythonPath 만 추가적으로 설정해 주면 된다.
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Python",
...
]
},
{
"name": "Python Console App",
...
},
{
"name": "Django",
"type": "python",
"pythonPath": "d:/envs/mydjangoenv/Scripts/python.exe",
"request": "launch",
"stopOnEntry": true,
"program": "${workspaceRoot}/manage.py",
"args": [
"runserver",
"--noreload",
"0.0.0.0:8080"
],
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput",
"DjangoDebugging"
]
}
]
}
Reference
- DonJayamanne/pythonVSCode, GitHub page
- Debugging · DonJayamanne/pythonVSCode Wiki · GitHub
- suggestion: choose python2 or python3 by !#/usr/bin/env python2/3 · Issue #17 · DonJayamanne/pythonVSCode · GitHub





댓글 없음:
댓글 쓰기