GNU/Linux >> Linux の 問題 >  >> Debian

Debian11にPIPPythonPackageManagerをインストールして使用する方法

Pipは、Pythonプログラミング言語で広く使用されているパッケージマネージャーです。 Python標準ライブラリでは利用できない追加のパッケージをインストールおよび管理するために使用されています。これにより、ユーザーはpython packages indexからパッケージを検索し、その依存関係をインストールできます。 Pipは、Pythonアプリケーション用に完全に分離された環境を作成できる「優先インストーラープログラム」とも呼ばれます。

この記事では、Debian11にPipをインストールして使用する方法を紹介します。

前提条件
  • Debian11を実行しているサーバー。
  • ルートパスワードはサーバーで構成されています。

Python3用のPipをインストール

デフォルトでは、PipはDebian11オペレーティングシステムにインストールされていません。 Python3とPython2に別々のPipバージョンをインストールする必要があります。

まず、次のコマンドを使用してPython3をインストールします。

apt-get install python3 -y

Python3パッケージがインストールされたら、次のコマンドを使用してPipforPython3をインストールします。

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: [email protected]
License: MIT
Location: /usr/lib/python3/dist-packages
Requires: 
Required-by: 

パッケージをアンインストールするには、次のコマンドを実行します。

pip3 uninstall scrapy
結論

上記のガイドでは、Debian 11にPip3とPip2をインストールする方法について説明しました。また、Pipコマンドを使用してPythonパッケージをインストールおよび管理する方法についても説明しました。 Pipコマンドを使用してPythonの依存関係を簡単に管理できるようになったことを願っています。


Debian
  1. Ubuntu20.04にSnapPackageManagerをインストールして使用する方法

  2. Debian11にAnsibleをインストールして使用する方法

  3. Debian11にNVMをインストールして使用する方法

  1. Debian11にMongoDBをインストールして保護する方法

  2. UbuntuにPipをインストールする方法–Python用パッケージマネージャー

  3. RockyLinux8にPIPPythonPackageManagerをインストールして使用する方法

  1. Debian9にPIPをインストールする方法

  2. Debianバックポートをインストールして使用する方法

  3. Debian10にPHPComposerをインストールして使用する方法