Python / PIP(Python Package Index) 사용법

Python Package Index

Python Package Index는 파이썬 패키지들이 모여 있는 저장소입니다. 2019년 3월 4일 현재 170,603개의 프로젝트, 1,236,475개의 릴리즈가 있습니다.

The Python Package Index (PyPI) is a repository of software for the Python programming language.

pip 명령어로 패키지를 로컬 머신에 설치하고 삭제하고 업데이트할 수 있습니다.

PIP

pip는 파이썬으로 작성된 패키지 소프트웨어를 관리하는 패키지 관리 시스템입니다. 파이썬 2.7.9 이후 버전과 파이썬 3.4 이후 버전은 pip를 기본적으로 포함하고 있습니다.

pip list

pip list 명령으로 현재 설치된 패키지 목록을 볼 수 있습니다. 업데이트가 필요한 패키지가 있는지도 알려줍니다.

C:\Users\JB>pip list
Package           Version
----------------- -------
astroid           2.2.1
colorama          0.4.1
isort             4.3.9
lazy-object-proxy 1.3.1
mccabe            0.6.1
pip               18.1
pylint            2.3.1
setuptools        40.6.2
six               1.12.0
typed-ast         1.3.1
typing            3.6.6
wrapt             1.11.1
You are using pip version 18.1, however version 19.0.3 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

pip show package-name

pip show 다음에 패키지 이름을 넣으면, 그 패키지 정보가 출력됩니다.

C:\Users\JB>pip show pip
Name: pip
Version: 18.1
Summary: The PyPA recommended tool for installing Python packages.
Home-page: https://pip.pypa.io/
Author: The pip developers
Author-email: pypa-dev@groups.google.com
License: MIT
Location: c:\users\jb\appdata\local\programs\python\python37-32\lib\site-packages
Requires:
Required-by:

pip install package-name

pip install 명령으로 패키지를 설치합니다.(flake8은 작성한 코드가 코드 작성 기준에 맞는지 검토하는 패키지입니다.)

C:\Users\JB>pip install flake8
Collecting flake8
  Downloading https://files.pythonhosted.org/packages/e9/76/b915bd28976068a9843bf836b789794aa4a8eb13338b23581005cd9177c0/flake8-3.7.7-py2.py3-none-any.whl (68kB)
    100% |████████████████████████████████| 71kB 849kB/s
Requirement already satisfied: mccabe<0.7.0,>=0.6.0 in c:\users\jb\appdata\roaming\python\python37\site-packages (from flake8) (0.6.1)
Collecting pycodestyle<2.6.0,>=2.5.0 (from flake8)
  Downloading https://files.pythonhosted.org/packages/0e/0c/04a353e104d2f324f8ee5f4b32012618c1c86dd79e52a433b64fceed511b/pycodestyle-2.5.0-py2.py3-none-any.whl (51kB)
    100% |████████████████████████████████| 51kB 1.3MB/s
Collecting pyflakes<2.2.0,>=2.1.0 (from flake8)
  Downloading https://files.pythonhosted.org/packages/84/f2/ed0ffb887f8138a8fe5a621b8c0bb9598bfb3989e029f6c6a85ee66628ee/pyflakes-2.1.1-py2.py3-none-any.whl (59kB)
    100% |████████████████████████████████| 61kB 1.4MB/s
Collecting entrypoints<0.4.0,>=0.3.0 (from flake8)
  Downloading https://files.pythonhosted.org/packages/ac/c6/44694103f8c221443ee6b0041f69e2740d89a25641e62fb4f2ee568f2f9c/entrypoints-0.3-py2.py3-none-any.whl
Installing collected packages: pycodestyle, pyflakes, entrypoints, flake8
Successfully installed entrypoints-0.3 flake8-3.7.7 pycodestyle-2.5.0 pyflakes-2.1.1

패키지를 업그레이드하고 싶다면 --upgrade 옵션을 붙입니다.

C:\Users\JB>pip install --upgrade flake8

pip uninstall package-name

pip uninstall 명령으로 패키지를 삭제합니다.

C:\Users\JB>pip uninstall flake8
Uninstalling flake8-3.7.7:
  Would remove:
    c:\users\jb\appdata\local\programs\python\python37-32\lib\site-packages\flake8-3.7.7.dist-info\*
    c:\users\jb\appdata\local\programs\python\python37-32\lib\site-packages\flake8\*
    c:\users\jb\appdata\local\programs\python\python37-32\scripts\flake8.exe
Proceed (y/n)? y
  Successfully uninstalled flake8-3.7.7

pip help

C:\Users\JB>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.
  config                      Manage local and global configuration.
  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.

General Options:
  -h, --help                  Show help.
  --isolated                  Run pip in an isolated mode, ignoring environment variables and user configuration.
  -v, --verbose               Give more output. Option is additive, and can be used up to 3 times.
  -V, --version               Show version and exit.
  -q, --quiet                 Give less output. Option is additive, and can be used up to 3 times (corresponding to
                              WARNING, ERROR, and CRITICAL logging levels).
  --log <path>                Path to a verbose appending log.
  --proxy <proxy>             Specify a proxy in the form [user:passwd@]proxy.server:port.
  --retries <retries>         Maximum number of retries each connection should attempt (default 5 times).
  --timeout <sec>             Set the socket timeout (default 15 seconds).
  --exists-action <action>    Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup,
                              (a)bort).
  --trusted-host <hostname>   Mark this host as trusted, even though it does not have valid or any HTTPS.
  --cert <path>               Path to alternate CA bundle.
  --client-cert <path>        Path to SSL client certificate, a single file containing the private key and the
                              certificate in PEM format.
  --cache-dir <dir>           Store the cache data in <dir>.
  --no-cache-dir              Disable the cache.
  --disable-pip-version-check
                              Don't periodically check PyPI to determine whether a new version of pip is available for
                              download. Implied with --no-index.
  --no-color                  Suppress colored output