웹사이트 검색

Debian 11에서 PIP Python 패키지 관리자를 설치하고 사용하는 방법


이 페이지에서

  1. 전제 조건
  2. Python3용 Pip 설치
  3. Python2용 Pip 설치
  4. Pip 명령줄 사용 방법
  5. 결론

Pip은 Python 프로그래밍 언어에 널리 사용되는 패키지 관리자입니다. Python 표준 라이브러리에서 사용할 수 없는 추가 패키지를 설치하고 관리하는 데 사용됩니다. 이를 통해 사용자는 Python 패키지 색인에서 패키지를 검색하고 종속성을 설치할 수 있습니다. Pip은 Python 애플리케이션에 대해 완전히 격리된 환경을 생성할 수 있는 "기본 설치 프로그램"으로도 알려져 있습니다.

이 기사에서는 Debian 11에서 Pip을 설치하고 사용하는 방법을 보여줍니다.

전제 조건

  • Debian 11을 실행하는 서버.\n
  • 루트 암호는 서버에서 구성됩니다.\n

Python3용 Pip 설치

기본적으로 Pip은 Debian 11 운영 체제에 설치되지 않습니다. Python3 및 Python2에 대해 별도의 Pip 버전을 설치해야 합니다.

먼저 다음 명령을 사용하여 Python3를 설치합니다.

apt-get install python3 -y

Python3 패키지가 설치되면 다음 명령을 사용하여 Python3용 Pip를 설치합니다.

apt-get install python3-pip -y

다음으로 다음 명령을 사용하여 Pip 버전을 확인합니다.

pip3 --version

다음과 같은 결과가 표시됩니다.

pip 20.3.4 from /usr/lib/python3/dist-packages/pip (python 3.9)

Python2용 Pip 설치

먼저 시스템에 Python2를 설치해야 합니다. 다음 명령을 사용하여 설치할 수 있습니다.

apt-get install python2 curl -y

다음으로 다음 명령을 사용하여 Pip2 설치 스크립트를 다운로드합니다.

curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py

그런 다음 다운로드한 스크립트를 실행하여 시스템에 Pip2를 설치합니다.

python2 get-pip.py

설치가 완료되면 다음 명령을 사용하여 Pip2 버전을 확인할 수 있습니다.

pip2 --version

다음과 같은 결과가 표시됩니다.

pip 20.3.4 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)

Pip 명령줄을 사용하는 방법

Pip에서 사용할 수 있는 모든 옵션을 나열하려면 다음 명령을 실행합니다.

pip3 --help

다음 목록이 표시됩니다.

Usage:   
  pip3  [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.
  cache                       Inspect and manage pip's wheel cache.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion.
  debug                       Show information useful for debugging.
  help                        Show help for commands.

TextStatistic과 같은 Python3용 패키지를 설치하려면 다음 명령을 실행합니다.

pip3 install "TextStatistic"

샘플 출력:

Collecting TextStatistic
  Downloading TextStatistic-1.0.6-py3-none-any.whl (5.6 kB)
Installing collected packages: TextStatistic
Successfully installed TextStatistic-1.0.6

scrapy와 같은 Python2용 패키지를 설치하려면 다음 명령을 실행합니다.

pip install "scrapy"

사용 가능한 모든 패키지를 나열하려면 다음 명령을 실행하십시오.

pip3 list

다음 출력이 표시되어야 합니다.

Package          Version
---------------- ---------
certifi          2020.6.20
chardet          4.0.0
httplib2         0.18.1
idna             2.10
pip              20.3.4
pycurl           7.43.0.6
PySimpleSOAP     1.16.2
python-apt       2.2.1
python-debian    0.1.39
python-debianbts 3.1.0
reportbug        7.10.3
requests         2.25.1
setuptools       52.0.0
six              1.16.0
TextStatistic    1.0.6
urllib3          1.26.5
wheel            0.34.2

패키지를 검색하려면 다음 명령을 실행합니다.

pip3 search urllib3

오래된 패키지를 나열하려면 다음 명령을 실행하십시오.

pip3 list --outdated

다음과 같은 결과가 표시됩니다.

Package          Version   Latest    Type
---------------- --------- --------- -----
certifi          2020.6.20 2021.10.8 wheel
httplib2         0.18.1    0.20.1    wheel
idna             2.10      3.3       wheel
pip              20.3.4    21.3      wheel
pycurl           7.43.0.6  7.44.1    sdist
python-debian    0.1.39    0.1.40    wheel
python-debianbts 3.1.0     3.2.0     wheel
requests         2.25.1    2.26.0    wheel
setuptools       52.0.0    58.2.0    wheel
urllib3          1.26.5    1.26.7    wheel
wheel            0.34.2    0.37.0    wheel

패키지 정보를 표시하려면 다음 명령을 실행하십시오.

pip3 show wheel

다음 출력에서 휠 패키지의 정보를 볼 수 있습니다.

Name: wheel
Version: 0.34.2
Summary: A built-package format for Python
Home-page: https://github.com/pypa/wheel
Author: Daniel Holth
Author-email: 
License: MIT
Location: /usr/lib/python3/dist-packages
Requires: 
Required-by: 

패키지를 제거하려면 다음 명령을 실행하십시오.

pip3 uninstall scrapy

결론

위 가이드에서는 Debian 11에 Pip3 및 Pip2를 설치하는 방법에 대해 설명했습니다. 또한 Pip 명령을 사용하여 Python 패키지를 설치하고 관리하는 방법도 설명했습니다. 이제 Pip 명령을 사용하여 Python 종속성을 쉽게 관리할 수 있기를 바랍니다.