개요
pip는 파이썬에서 사용하는 패키지 관리 도구이다. 이 글은 pip를 이용하여 현재 설치된 파이썬 패키지를 일괄적으로 버전 업데이트 하는 방법 소개를 목적으로 한다. 이에 앞서 pip에서 사용할 옵션과 명령을 살펴보고, 이후 설치된 파이썬 패키지를 업데이트 한다.
pip 옵션 및 명령
pip의 기능을 살펴보기 위해 pip --help를 통해 살펴보면 다음과 같다.
Usage:
pip <command> [options]
Commands:
install Install packages.
download Download packages.
uninstall Uninstall packages.
freeze Output installed packages in requirements format.
list List installed packages.
show Show information about installed packages.
check Verify installed packages have compatible dependencies.
search Search PyPI for packages.
wheel Build wheels from your requirements.
hash Compute hashes of package archives.
completion A helper command used for command completion.
help Show help for commands.
명령어 중에서 사용할 것은 install 명령어와 freeze 명령어를 사용할 것이다. install 명령어에서는 pip install --upgrade(-U) 옵션과 --requirement(-r) 옵션을 통해서 설치되어 있는 파이썬 패키지들을 업데이트 한다. --upgrade는 말 그대로 기존의 패키지를 버전 업하는 것이며 --requirement 옵션은 pip의 requirement 형식의 파일로 부터 패키지 이름과 버전을 입력으로 받아 install 명령어를 수행하는 것이다.
먼저 freeze 명령어를 통해 requirement 파일을 만들어보자.
$ pip3 freeze > pip_requirement
다음은 pip requirement 형식 파일을 살펴보자. freeze 명령어는 수행 시점의 패키지 목록과 각 패키지의 버전을 표시하는데 이를 개발 환경 구축과 같은 경우에는 적합하나 패키지를 전체적으로 업데이트 하기 위해서는 버전 명시가 없어야 된다. 그러므로 정규표현식을 통해서 버전 명시부분을 지우고 패키지 이름만을 남기도록 하자.
appdirs==1.4.3
apturl==0.5.2
asn1crypto==0.21.1
beautifulsoup4==4.5.3
blinker==1.4
bottle==0.12.13
Brlapi==0.6.4
cffi==1.9.1
chardet==2.3.0
checkbox-support==0.33.0
click==6.7
command-not-found==0.3
cryptography==1.8.1
defer==1.0.6
feedparser==5.2.1
Flask==0.12
guacamole==0.9.2
html5lib==0.999999999
httplib2==0.10.3
idna==2.5
itsdangerous==0.24
Jinja2==2.9.5
language-selector==0.1
louis==2.6.4
lxml==3.7.3
...
Upgrade packages
이후 pip 명령어를 통해서 다음명령어를 통해서 패키지 업데이트를 수행한다.
$ sudo pip3 install --upgrade -r pip_requirement
Requirement already up-to-date: appdirs in /usr/local/lib/python3.5/dist-packages (from -r pip_requirement (line 1))
Requirement already up-to-date: apturl in /usr/lib/python3/dist-packages (from -r pip_requirement (line 2))
Requirement already up-to-date: asn1crypto in /usr/local/lib/python3.5/dist-packages (from -r pip_requirement (line 3))
Requirement already up-to-date: beautifulsoup4 in /usr/local/lib/python3.5/dist-packages (from -r pip_requirement (line 4))
Requirement already up-to-date: blinker in /usr/local/lib/python3.5/dist-packages (from -r pip_requirement (line 5))
Requirement already up-to-date: bottle in /usr/local/lib/python3.5/dist-packages (from -r pip_requirement (line 6))
Requirement already up-to-date: Brlapi in /usr/lib/python3/dist-packages (from -r pip_requirement (line 7))
Requirement already up-to-date: cffi in /usr/local/lib/python3.5/dist-packages (from -r pip_requirement (line 8))
...
위의 방법이외에도 여러가지 방법이 참조한 페이지에 열거되어 있다. 다른 방법을 원한다면 아래의 참조 링크를 참고하면 된다.