Python 서버 마이그레이션 가이드
Python 서버 이전 시 가상 환경 및 의존성 설정 방법
Python 서버를 새 환경(예: EC2)으로 마이그레이션할 때 다음 단계를 따르면 됨.
- 엔드포인트 URL 재작성: 필요한 경우 API 엔드포인트 URL을 새 서버에 맞게 수정해야 함.
- 로컬에서 모듈 동결: 현재 프로젝트의 의존성 목록을
requirements.txt파일로 생성해두면 됨.bash pip freeze > requirements.txt - EC2 등 새 서버에서 환경 설정:
- 프로젝트 폴더로 이동.
- 가상 환경 생성:
python버전은 프로젝트에 맞게 지정 (예:python3.8).bash python3.8 -m venv ./venv - 가상 환경 활성화:
bash source venv/bin/activate - 의존성 설치: 이전에 생성한
requirements.txt파일을 이용해 필요한 패키지를 설치함.bash pip install -r requirements.txt python3명령어로 정상 실행되는지 테스트하면 끝!
여기서 배울 것
- Python 프로젝트 의존성을 `requirements.txt`로 관리하는 법
- 새 서버에 Python 가상 환경을 생성하고 활성화하는 법
- pip를 이용해 `requirements.txt`에서 패키지를 설치하는 법
- 서버 마이그레이션 시 필요한 기본 Python 환경 설정 절차
원본 파일 보기 (.claude/skills/tn-python-server-migration/SKILL.md)
---
name: Python 서버 마이그레이션 환경 설정
description: Use when the user needs to migrate a Python server, set up its virtual environment, or install dependencies on a new machine like EC2.
version: 1.0.0
source: /home/son/prj/resume/backup_notes_260317/notion/Tech Note/python server migration 5e5ea34b4fed4d37b4933a53f67c5520.md
---
# python server migration
1. rewrite endpoint url
2. join venv in local

3. freeze modules
```jsx
pip freeze -r "requirement.txt"
```
1. move to EC2
1. go to project folder
2. setup the venv
`python -m venv /path/to/new/virtual/environment`
in our case,
```jsx
python3.8 -m venv ./venv
```
3. active venv
4. install requirement.txt

5. test with python3 execution.
GOGO!