VS Code로 Python 개발 시작하기 - glasslego/getting-started-with-python GitHub Wiki
1. VS Code 설치
- 공식 다운로드: https://code.visualstudio.com
- Windows / macOS / Linux 모두 지원
2. Python 확장팩 설치
- 좌측 Extensions 아이콘(🧩) 클릭
Python
입력 → Microsoft Python Extension 설치
✅ 주요 기능:
- 자동 Python 인터프리터 인식
- 코드 자동완성 (Pylance)
- Linting, Formatting, 디버깅, 테스트 통합
3. 가상환경 선택 (venv, poetry, pyenv, uv)
- VS Code 좌측 하단의
Python: x.x.x
클릭 - 현재 프로젝트의
.venv
,poetry
,pyenv
환경 자동 탐지 - 원하는 인터프리터 선택
(예:~/.pyenv/versions/3.11.7/bin/python
)
4. Linting / Formatting 설정
.vscode/settings.json
파일 생성:
- Linter 설정 (코드 오류 및 스타일 검사)
- 린터(Linter)는 코드를 분석해서 문법적인 오류, 잠재적인 버그, 스타일 규칙 위반 등을 찾아주는 도구(마치 글을 쓸 때 맞춤법 검사기와 같은 역할)
- Formatter 설정 (코드 스타일 자동 정리)
- 포맷터(Formatter)는 정해진 규칙에 따라 코드의 스타일(들여쓰기, 줄 바꿈, 따옴표 등)을 자동으로 예쁘게 정리해주는 도구
{
"python.linting.enabled": true,
"python.linting.flake8Enabled": true,
"editor.formatOnSave": true,
"python.formatting.provider": "black"
}
5. 테스트 실행 (pytest)
poetry add pytest --group dev
json 설정
- tests/ 폴더에 테스트 코드를 넣으면 자동 탐지됩니다.
{
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": ["tests"]
}
6. 디버깅
- .py 파일에서 중단점(🔴) 클릭
- F5 또는 Run → Start Debugging
- 자동으로 .vscode/launch.json 생성됨
7. 프로젝트 구조 예시
my-project/
├── .vscode/
│ ├── settings.json # VS Code 설정
│ ├── launch.json # 디버깅 설정
│ └── extensions.json # 추천 확장 프로그램
├── .venv/ # 가상환경
├── src/
│ └── my_project/ # 패키지 이름 (하이픈 → 언더스코어)
│ ├── __init__.py # 패키지 초기화
│ ├── main.py # 메인 로직
│ ├── config.py # 설정 관리
│ ├── utils/
│ │ ├── __init__.py
│ │ ├── helpers.py # 유틸리티 함수
│ │ └── validators.py # 검증 함수
│ └── models/
│ ├── __init__.py
│ └── user.py # 데이터 모델
├── tests/
│ ├── __init__.py
│ ├── conftest.py # pytest 설정
│ ├── test_main.py # 메인 테스트
│ ├── test_utils/
│ │ ├── __init__.py
│ │ └── test_helpers.py # 유틸리티 테스트
│ └── test_models/
│ ├── __init__.py
│ └── test_user.py # 모델 테스트
├── docs/ # 문서
│ ├── README.md
│ └── api.md
├── scripts/ # 스크립트
│ ├── setup.sh
│ └── deploy.sh
├── .env.example # 환경변수 예시
├── .gitignore # Git 무시 파일
├── README.md # 프로젝트 설명
└── pyproject.toml # 프로젝트 설정
8. 추천 확장팩
- python (Microsoft 공식 Python 플러그인)
- pylance (빠르고 정확한 IntelliSense)
- Black Formatter (코드 자동 정렬)
- Flake8 (lint 도구)
- Jupyter (노트북 형식 실행)
- Code Runner (코드 빠른 실행 도구)