GNU/Linux >> Linux の 問題 >  >> Cent OS

CentOS 8 /RHEL8にPipをインストールする方法

Pip(Pip Installs Package)は、Pythonソフトウェアパッケージをインストールできるパッケージ管理システムです。 Python Package Index(PyPI)にリストされているPythonパッケージをインストールします。

ピップバージョン

CentOS 8 /RHEL8で使用できるPipには2つのバージョンがあります。

  • Python 3用のPip(pip3)
  • Python 2用のPip(pip2)

この投稿では、CentOS 8 /RHEL8に両方のバージョンのPipをインストールする方法を説明します。

Pipのインストールとは別に、Pipを使用してPythonパッケージを管理する方法も説明します。

Python3用のPipをインストール

Pip for Python 3(pip3)は、Python3パッケージによって提供されます。以下のコマンドを使用してインストールできます。

dnf install -y python3
Output:

CentOS-8 - AppStream                                                   1.5 MB/s | 6.5 MB     00:04
CentOS-8 - Base                                                        232 kB/s | 5.0 MB     00:22
CentOS-8 - Extras                                                      594  B/s | 2.1 kB     00:03
Dependencies resolved.
=======================================================================================================
 Package                        Arch       Version                                 Repository     Size
=======================================================================================================
Installing:
 python36                       x86_64     3.6.8-2.module_el8.1.0+245+c39af44f     AppStream      19 k
Upgrading:
 platform-python-pip            noarch     9.0.3-15.el8                            BaseOS        1.8 M
 platform-python-setuptools     noarch     39.2.0-5.el8                            BaseOS        632 k
Installing dependencies:
 python3-pip                    noarch     9.0.3-15.el8                            AppStream      19 k
 python3-setuptools             noarch     39.2.0-5.el8                            BaseOS        162 k
Enabling module streams:
 python36                                  3.6

Transaction Summary
=======================================================================================================
Install  3 Packages
Upgrade  2 Packages

Total download size: 2.6 M
Downloading Packages:
CentOS-8 - AppStream            195% [============================================================-] 1.(1/5): python3-pip-9.0.3-15.el8.noarch.rpm                              16 kB/s |  19 kB     00:01
(2/5): python36-3.6.8-2.module_el8.1.0+245+c39af44f.x86_64.rpm          16 kB/s |  19 kB     00:01
(3/5): python3-setuptools-39.2.0-5.el8.noarch.rpm                      100 kB/s | 162 kB     00:01
(4/5): platform-python-setuptools-39.2.0-5.el8.noarch.rpm              353 kB/s | 632 kB     00:01
[MIRROR] platform-python-pip-9.0.3-15.el8.noarch.rpm: Curl error (28): Timeout was reached for http://centos.mirror.snu.edu.in/centos/8.1.1911/BaseOS/x86_64/os/Packages/platform-python-pip-9.0.3-15.el8.noarch.rpm [Connection timed out after 30001 milliseconds]
(5/5): platform-python-pip-9.0.3-15.el8.noarch.rpm                      60 kB/s | 1.8 MB     00:31
-------------------------------------------------------------------------------------------------------
Total                                                                   76 kB/s | 2.6 MB     00:35
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                               1/1
  Upgrading        : platform-python-setuptools-39.2.0-5.el8.noarch                                1/7
  Installing       : python3-setuptools-39.2.0-5.el8.noarch                                        2/7
  Upgrading        : platform-python-pip-9.0.3-15.el8.noarch                                       3/7
  Installing       : python36-3.6.8-2.module_el8.1.0+245+c39af44f.x86_64                           4/7
  Running scriptlet: python36-3.6.8-2.module_el8.1.0+245+c39af44f.x86_64                           4/7
  Installing       : python3-pip-9.0.3-15.el8.noarch                                               5/7
  Cleanup          : platform-python-pip-9.0.3-13.el8.noarch                                       6/7
  Cleanup          : platform-python-setuptools-39.2.0-4.el8.noarch                                7/7
  Running scriptlet: platform-python-setuptools-39.2.0-4.el8.noarch                                7/7
  Verifying        : python3-pip-9.0.3-15.el8.noarch                                               1/7
  Verifying        : python36-3.6.8-2.module_el8.1.0+245+c39af44f.x86_64                           2/7
  Verifying        : python3-setuptools-39.2.0-5.el8.noarch                                        3/7
  Verifying        : platform-python-pip-9.0.3-15.el8.noarch                                       4/7
  Verifying        : platform-python-pip-9.0.3-13.el8.noarch                                       5/7
  Verifying        : platform-python-setuptools-39.2.0-5.el8.noarch                                6/7
  Verifying        : platform-python-setuptools-39.2.0-4.el8.noarch                                7/7

Upgraded:
  platform-python-pip-9.0.3-15.el8.noarch        platform-python-setuptools-39.2.0-5.el8.noarch

Installed:
  python36-3.6.8-2.module_el8.1.0+245+c39af44f.x86_64          python3-pip-9.0.3-15.el8.noarch
  python3-setuptools-39.2.0-5.el8.noarch

Complete!

以下のコマンドを使用して、Pythonのバージョンを確認します。

python3 --version
Output:

Python 3.6.8

上記の出力は、システムにPython3がインストールされていることを示しています。

これで、システムにpip3コマンドが含まれるはずです。

pip3 --version
Output:

pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6)

pipのバージョンは、オペレーティングシステムとリリース日によって異なる場合があります。

Python2用のPipをインストール

Pip for Python 2(pip2)は、Python2パッケージによって提供されます。デフォルトでは、Python2パッケージはCentOS8 /RHEL8にインストールされていません。

以下のコマンドを使用してPython2パッケージをインストールします。

dnf install -y python2
Output:
CentOS-8 - AppStream                                                   1.3 MB/s | 6.5 MB     00:04
CentOS-8 - Base                                                        152 kB/s | 5.0 MB     00:33
CentOS-8 - Extras                                                      488  B/s | 2.1 kB     00:04
Last metadata expiration check: 0:00:01 ago on Fri 06 Mar 2020 08:47:10 AM EST.
Dependencies resolved.
=======================================================================================================
 Package                      Arch       Version                                   Repository     Size
=======================================================================================================
Installing:
 python2                      x86_64     2.7.16-12.module_el8.1.0+219+cf9e6ac9     AppStream     109 k
Installing dependencies:
 python2-libs                 x86_64     2.7.16-12.module_el8.1.0+219+cf9e6ac9     AppStream     6.0 M
 python2-pip-wheel            noarch     9.0.3-14.module_el8.1.0+219+cf9e6ac9      AppStream     1.2 M
 python2-setuptools-wheel     noarch     39.0.1-11.module_el8.1.0+219+cf9e6ac9     AppStream     289 k
Installing weak dependencies:
 python2-pip                  noarch     9.0.3-14.module_el8.1.0+219+cf9e6ac9      AppStream     2.0 M
 python2-setuptools           noarch     39.0.1-11.module_el8.1.0+219+cf9e6ac9     AppStream     643 k
Enabling module streams:
 python27                                2.7

Transaction Summary
=======================================================================================================
Install  6 Packages

Total download size: 10 M
Installed size: 39 M
Downloading Packages:
(1/6): python2-2.7.16-12.module_el8.1.0+219+cf9e6ac9.x86_64.rpm         82 kB/s | 109 kB     00:01
(2/6): python2-pip-wheel-9.0.3-14.module_el8.1.0+219+cf9e6ac9.noarch.r 3.3 MB/s | 1.2 MB     00:00
(3/6): python2-setuptools-39.0.1-11.module_el8.1.0+219+cf9e6ac9.noarch 3.4 MB/s | 643 kB     00:00
(4/6): python2-setuptools-wheel-39.0.1-11.module_el8.1.0+219+cf9e6ac9. 2.4 MB/s | 289 kB     00:00
(5/6): python2-pip-9.0.3-14.module_el8.1.0+219+cf9e6ac9.noarch.rpm     1.0 MB/s | 2.0 MB     00:02
(6/6): python2-libs-2.7.16-12.module_el8.1.0+219+cf9e6ac9.x86_64.rpm   2.6 MB/s | 6.0 MB     00:02
-------------------------------------------------------------------------------------------------------
Total                                                                  2.7 MB/s |  10 MB     00:03
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                               1/1
  Installing       : python2-setuptools-wheel-39.0.1-11.module_el8.1.0+219+cf9e6ac9.noarch         1/6
  Installing       : python2-pip-wheel-9.0.3-14.module_el8.1.0+219+cf9e6ac9.noarch                 2/6
  Installing       : python2-libs-2.7.16-12.module_el8.1.0+219+cf9e6ac9.x86_64                     3/6
  Installing       : python2-pip-9.0.3-14.module_el8.1.0+219+cf9e6ac9.noarch                       4/6
  Installing       : python2-setuptools-39.0.1-11.module_el8.1.0+219+cf9e6ac9.noarch               5/6
  Installing       : python2-2.7.16-12.module_el8.1.0+219+cf9e6ac9.x86_64                          6/6
  Running scriptlet: python2-2.7.16-12.module_el8.1.0+219+cf9e6ac9.x86_64                          6/6
  Verifying        : python2-2.7.16-12.module_el8.1.0+219+cf9e6ac9.x86_64                          1/6
  Verifying        : python2-libs-2.7.16-12.module_el8.1.0+219+cf9e6ac9.x86_64                     2/6
  Verifying        : python2-pip-9.0.3-14.module_el8.1.0+219+cf9e6ac9.noarch                       3/6
  Verifying        : python2-pip-wheel-9.0.3-14.module_el8.1.0+219+cf9e6ac9.noarch                 4/6
  Verifying        : python2-setuptools-39.0.1-11.module_el8.1.0+219+cf9e6ac9.noarch               5/6
  Verifying        : python2-setuptools-wheel-39.0.1-11.module_el8.1.0+219+cf9e6ac9.noarch         6/6

Installed:
  python2-2.7.16-12.module_el8.1.0+219+cf9e6ac9.x86_64
  python2-pip-9.0.3-14.module_el8.1.0+219+cf9e6ac9.noarch
  python2-setuptools-39.0.1-11.module_el8.1.0+219+cf9e6ac9.noarch
  python2-libs-2.7.16-12.module_el8.1.0+219+cf9e6ac9.x86_64
  python2-pip-wheel-9.0.3-14.module_el8.1.0+219+cf9e6ac9.noarch
  python2-setuptools-wheel-39.0.1-11.module_el8.1.0+219+cf9e6ac9.noarch

Complete!

以下のコマンドを使用して、Pythonのバージョンを確認します。

python2 --version
Output:

Python 2.7.16

上記の出力は、システムにPython2がインストールされていることを示しています。

Pipのバージョンも確認してください。

pip2 --version
Output:

pip 9.0.3 from /usr/lib/python2.7/site-packages (python 2.7)

上記の出力は、Python2のpipが正常にインストールされたことを確認します。 pipのバージョンは、オペレーティングシステムとリリース日によって異なる場合があります。

Pipの使用方法

Pipコマンドの基本をいくつか説明します。

Python 2を使用している場合は、コマンドでpip3をpip2に置き換えます。

Pipを使用してパッケージをインストールする

Pipを使用してパッケージをインストールするには、以下のコマンドを使用できます。

pip3 install PACKAGE_NAME

たとえば、強力なインタラクティブPythonシェルである最新バージョンのIPythonパッケージをインストールするには、次のコマンドを使用します。

pip3 install IPython

上記のコマンドは、必要なすべてのファイルをダウンロードし、指定されたパッケージをインストールします。

パッケージの特定のバージョン(例6.0)をインストールするには、以下のコマンドを使用できます。

pip3 install IPython==6.0
インストールされているPipパッケージのリスト

インストールされているPythonパッケージを一覧表示するには、次のコマンドを使用します。

pip3 list
Output:

.       .       .

gpg (1.10.0)
idna (2.5)
iniparse (0.4)
ipython (7.13.0)
ipython-genutils (0.2.0)
jedi (0.16.0)
netifaces (0.10.6)
parso (0.6.2)

.      .       .
Pipを使用してパッケージをアップグレードする

パッケージを最新バージョンにアップグレードするには、以下のコマンドを使用します。

pip3 install --upgrade IPython
Pipを使用してパッケージを削除する

pipを介してインストールされたパッケージを削除する場合は、以下のコマンドを使用できます。

pip3 uninstall IPython

Pipを使用してパッケージを検索

Pipの検索機能を使用すると、パッケージ(名前)を検索できます。このコマンドは、PyPI(Python Package Index)からパッケージリストを取得します。

pip3 search google
Output:

google (2.0.2) - Python bindings to the Google search engine.
oauthkit-google (0.1.2) - OAuthKit for Google
bits-google (1.8.6) - BITS Google
google-gax (0.16.0) - Google API Extensions
google-finance (0.1.0) - Google Finance API
google-oauth (1.0.1) - OAuth2 for Google APIs
google-auth (1.6.3) - Google Authentication Library

.     .     .
結論

それで全部です。 CentOS 8 / RHEL 8にPipをインストールする方法と、Pythonパッケージを管理するためのコマンド構文を学習したことを願っています。 Pipの詳細については、Pipのユーザーガイドページにアクセスしてください。


Cent OS
  1. CentOS8にPipをインストールする方法

  2. RHEL 8 /CentOS8にphpMyAdminをインストールする方法

  3. RHEL 8 /CentOS8にP7Zipをインストールする方法

  1. RHEL 8 /CentOS8にntfs-3gをインストールする方法

  2. PHP-mbstringをRHEL8/CentOS8にインストールする方法

  3. RHEL 8 /CentOS8にphantomjsをインストールする方法

  1. DropboxをRHEL8/CentOS8にインストールする方法

  2. RHEL 8 /CentOS8にコンパスをインストールする方法

  3. RHEL 8 /CentOS8にpipをインストールする方法