PHpullh
학습 라이브러리/Python/pip 패키지 관리

PYTHON · Hello World

pip 패키지 관리

Python의 패키지 관리자 pip를 사용하여 외부 라이브러리를 설치하고 requirements.txt로 의존성을 관리합니다.

Hello World입문piprequirements패키지install

핵심 설명

Python의 패키지 관리자 pip를 사용하여 외부 라이브러리를 설치하고 requirements.txt로 의존성을 관리합니다.

Python code

import subprocess, sys

# 패키지 설치 / 업그레이드 / 삭제
# pip install requests
# pip install requests==2.31.0
# pip install --upgrade requests
# pip uninstall requests

# 설치된 패키지 목록
# pip list
# pip freeze > requirements.txt

# requirements.txt에서 일괄 설치
# pip install -r requirements.txt

# 프로그래밍 방식으로 설치된 패키지 확인
from importlib.metadata import distributions
installed = {d.metadata["Name"]: d.version
             for d in distributions()}
for name in sorted(installed)[:5]:
    print(f"{name}=={installed[name]}")

학습 팁

pip freeze 대신 pip-compile(pip-tools)을 쓰면 직접 의존성과 간접 의존성을 분리 관리할 수 있습니다.

주의할 점

pip install 시 버전을 고정하지 않으면 환경마다 다른 버전이 설치되어 "내 컴퓨터에서는 되는데" 문제가 발생합니다.

자주 묻는 질문

pip 패키지 관리란 무엇인가요?

Python의 패키지 관리자 pip 를 사용하여 외부 라이브러리를 설치하고 requirements.txt 로 의존성을 관리합니다.

pip 패키지 관리 학습 시 주의할 점은 무엇인가요?

pip install 시 버전을 고정하지 않으면 환경마다 다른 버전이 설치되어 "내 컴퓨터에서는 되는데" 문제가 발생합니다.

Continue Learning

Python 학습을 이어가세요

총 200개의 독립 HTML 학습 문서 중 하나입니다. 각 문서는 고유 URL과 canonical 메타데이터를 가집니다.