Windows OS + VS Code + Git 환경에서 실습할 수 있는 단순한 Python 프로젝트 구조와 워크플로우입니다. API 키는 secrets.env에 저장하고 os 라이브러리로 불러오며, numpy와 matplotlib 같은 외부 패키지는 venv와 requirements.txt로 관리합니다. 마지막으로, GitHub 연동 및 public repo로 push하는 CLI 명령어도 포함합니다.
venv를 쓰면 프로젝트 간 라이브러리 격리, 충돌 방지, 협업과 배포 효율이라는 실용적 이점을 가짐. 필요하면.venv을.gitignore에 넣어서 Git으로 관리되지 않게 할 수도 있음.
bash
# 1. 가상환경 생성
python -m venv .venv
# 2. 가상환경 활성화 (Mac/Linux)
source .venv/bin/activate
# (Windows)
.venv\Scripts\activate
📌 요약
secrets.env+dotenv→ 안전한 키 관리requirements.txt+venv→ 환경 일관성- Git CLI + GitHub 연동 → 버전 관리 및 배포 연습
- VS Code 자동 Git 연동 → 확장 없이도 실시간 동기화 가능
✅ 1. 프로젝트 구조
plain text
first-project/
├── /.venv
├── main.py
├── requirements.txt
├── .gitignore
├── secrets.env
✅ 2. 프로젝트 생성 및 초기화 (CLI)
shell
mkdir first-project
cd first-project
# Python 가상 환경 생성
python -m venv .venv
# 가상 환경 활성화 (Windows)
.venv\Scripts\activate
# 기본 파일 생성
# WSL 환경
touch main.py requirements.txt .gitignore secrets.env
# 기본 windows os 환경
New-Item main.py, requirements.txt, .gitignore, secrets.env -ItemType File✅ 3. secrets.env 설정 및 사용
[secrets.env]
plain text
API_KEY=your_real_api_key_here[main.py]
python
import os
from dotenv import load_dotenv
import numpy as np
import matplotlib.pyplot as plt
# Load secrets
load_dotenv("secrets.env")
api_key = os.getenv("API_KEY")
print(f"My API Key is: {api_key}")
# Use numpy and matplotlib
x = np.linspace(0, 10, 100)
y = np.sin(x)
plt.plot(x, y)
plt.title("Simple Plot")
plt.show()✅ 4. requirements.txt 관련
패키지 설치 후 자동 목록 저장
bash
# 패키지 설치
pip install numpy pandas python-dotenv
# 설치 목록 저장
pip freeze > requirements.txt목록 저장 후 패키지 자동 설치
requirements.txt 파일에 아래 내용을 입력
plain text
numpy
matplotlib
python-dotenv설치:
shell
pip install -r requirements.txt✅ 5. .gitignore 설정
[.gitignore]
plain text
.venv/
__pycache__/
secrets.env✅ 6. Git 초기화 및 GitHub 연동
6.1 로컬 Git 초기화
shell
git init
git add .
git commit -m "Initial commit"6.2 GitHub에서 public repository 생성 (웹에서 수동으로 simple-project 생성)
6.3 원격 연결 및 push
shell
git remote add origin https://github.com/your-username/simple-project.git
git branch -M main
git push -u origin main
✅ 7. VS Code에서 열기
shell
code .
VS Code에서 자동으로 Git이 활성화됩니다. GitHub 확장을 따로 설치하지 않아도, Windows + Git + GitHub 계정 연결만 되어 있다면 GitHub 리포지토리 동기화 기능은 바로 작동합니다.