Python 관련 패키지를 설치 및 관리할 수 있는 pip 명령어에 대한 내용을 정리합니다.
테스트 환경
ㅇ OS : CentOS 8.1
(venv) [jackerlab@jackerlab ~]$ cat /etc/redhat-release
CentOS Linux release 8.1.1911 (Core)
(venv) [jackerlab@jackerlab ~]$
ㅇ Python : 3.6.8
(venv) [jackerlab@jackerlab ~]$ python --version
Python 3.6.8
(venv) [jackerlab@jackerlab ~]$
pip 버전 확인
# pip --version
(venv) [jackerlab@jackerlab ~]$ pip --version
pip 20.1.1 from /home/jackerlab/jackerlab_project/venv/lib/python3.6/site-packages/pip (python 3.6)
(venv) [jackerlab@jackerlab ~]$
pip 버전 업그레이드
# pip install -U pip
(venv) [jackerlab@jackerlab ~]$ pip install -U pip
Requirement already up-to-date: pip in ./jackerlab_project/venv/lib/python3.6/site-packages (20.1.1)
(venv) [jackerlab@jackerlab ~]$
패키지 목록 확인
# pip list
(venv) [jackerlab@jackerlab ~]$ pip list
Package Version
---------- -------
asgiref 3.2.7
Django 3.0.7
nodeenv 1.3.5
pip 20.1.1
pytz 2020.1
setuptools 46.4.0
sqlparse 0.3.1
wheel 0.34.2
(venv) [jackerlab@jackerlab ~]$
패키지 설치
# pip install [패키지명]
(venv) [jackerlab@jackerlab ~]$ pip install ipaddress
Collecting ipaddress
Using cached ipaddress-1.0.23-py2.py3-none-any.whl (18 kB)
Installing collected packages: ipaddress
Successfully installed ipaddress-1.0.23
(venv) [jackerlab@jackerlab ~]$
패키지 최신 버전 및 업그레이드 필요 여부 확인
# pip list -o
(venv) [jackerlab@jackerlab ~]$ pip list -o
Package Version Latest Type
---------- ------- ------ -----
nodeenv 1.3.5 1.4.0 wheel
setuptools 46.4.0 47.1.1 wheel
(venv) [jackerlab@jackerlab ~]$
패키지 업그레이드
# pip install ipaddress --upgrade
(venv) [jackerlab@jackerlab ~]$ pip install ipaddress --upgrade
Requirement already up-to-date: ipaddress in ./jackerlab_project/venv/lib/python3.6/site-packages (1.0.23)
(venv) [jackerlab@jackerlab ~]$
pip requirements 파일 생성
# pip freeze > requirements.txt
(venv) [jackerlab@jackerlab ~]$ pip freeze > requirements.txt
(venv) [jackerlab@jackerlab ~]$ cat requirements.txt
asgiref==3.2.7
Django==3.0.7
ipaddress==1.0.23
nodeenv==1.3.5
pytz==2020.1
sqlparse==0.3.1
(venv) [jackerlab@jackerlab ~]$
requirements 파일로 패키지 일괄 설치
# pip install -r requirements.txt
(venv) [jackerlab@jackerlab jackerlab_backend]$ pip install -r requirements.txt
Collecting asgiref==3.2.5
Using cached asgiref-3.2.5-py2.py3-none-any.whl (19 kB)
Collecting astroid==2.3.3
Using cached astroid-2.3.3-py3-none-any.whl (205 kB)
Collecting attrs==19.3.0
Using cached attrs-19.3.0-py2.py3-none-any.whl (39 kB)
...
패키지 삭제
# pip uninstall [패키지명]
(venv) [jackerlab@jackerlab ~]$ pip uninstall ipaddress
Found existing installation: ipaddress 1.0.23
Uninstalling ipaddress-1.0.23:
Would remove:
/home/jackerlab/jackerlab_project/venv/lib/python3.6/site-packages/ipaddress-1.0.23.dist-info/*
/home/jackerlab/jackerlab_project/venv/lib/python3.6/site-packages/ipaddress.py
Proceed (y/n)? y
Successfully uninstalled ipaddress-1.0.23
(venv) [jackerlab@jackerlab ~]$