반응형
requirements.txt 는 Python 프로젝트에서 필요한 패키지를 명시하고 쉽게 설치할 수 있도록 도와주는 파일입니다.
[🚀 Dev/Python] - [Python] requirements.txt 명령어 정리
[Python] requirements.txt 명령어 정리
Python 프로젝트를 하다 보면 requirements.txt는 빠질 수 없는 필수 구성이다.이 파일 하나로 필요한 패키지들을 한번에 설치하거나, 현재 프로젝트에서 어떤 패키지를 사용하는지 기록할 수 있다.잘
jeeqong.tistory.com
1. requirements.txt 파일 생성 방법
1.1 직접 작성
requirements.txt 파일을 생성하고 필요한 패키지를 수동으로 입력할 수 있다.
fastapi
uvicorn
selenium
beautifulsoup4
pandas
scikit-learn
spacy
1.2 현재 환경의 패키지를 기반으로 생성
현재 Python 가상 환경(venv)에서 설치된 모든 패키지를 requirements.txt 파일로 저장하려면 다음 명령어를 실행!!
pip freeze > requirements.txt
2. requirements.txt를 사용하여 패키지 설치
프로젝트를 새로 설정할 때 requirements.txt에 명시된 패키지를 한 번에 설치하려면 다음 명령어를 실행요.
pip install -r requirements.txt
3. requirements.txt 예제
아래는 예제 requirements.txt 파일입니다.
fastapi==0.95.1
uvicorn==0.20.0
selenium==4.8.2
beautifulsoup4==4.12.2
pandas==1.5.3
scikit-learn==1.2.2
spacy==3.5.2
psycopg2-binary==2.9.6
각 패키지 뒤의 ==버전은 특정 버전을 지정하는 방법입니다.
특정 버전이 필요 없다면 버전 번호 없이 패키지 이름만 입력할 수도 있다.
4. requirements.txt 파일 유지보수
4.1 패키지 업데이트
pip install --upgrade -r requirements.txt
4.2 패키지 목록 갱신
새로운 패키지를 설치한 후 requirements.txt를 업데이트하려면:
pip freeze > requirements.txt
반응형
'Dev > Python' 카테고리의 다른 글
🚨[Alembic] 명령어 및 오류 설정확인 (0) | 2025.03.20 |
---|---|
[FastAPI] FastAPI+ Alembic 설정 및 프로세스 정리 (0) | 2025.03.19 |
[Python] Code Formatter 코드포매터 (0) | 2025.03.17 |
[FastAPI] Alembic migrations/env.py 수정하여 특정 테이블 무시 (0) | 2025.03.15 |
🚨[Python] package import error (0) | 2025.03.15 |