Cara menginstal Pip di CentOS 8

Posted on

[ad_1] Cara menginstal Pip di CentOS 8

Instal centos pip

Dalam tutorial ini, kita akan menginstal pip pada CentOS 8 menggunakan manajer paket yum dan membahas dasar-dasar cara menginstal dan mengelola paket python dengan pip. Di repositori AppStream CentOS 8, ada kedua versi pip untuk Python 2 serta juru bahasa Python 3. Perintah pip sekarang berjalan dengan perintah pip2 atau pip3, masing-masing.

Apa itu PIP?

pip adalah manajer paket (modul) standar Python. Ini memungkinkan Anda untuk menginstal dan mengelola paket tambahan yang bukan bagian dari pustaka standar Python. Modul adalah pustaka kode Python yang dapat Anda sertakan dan gunakan dalam proyek Anda. pip telah disertakan dengan penginstal Python sejak versi 3.4 untuk Python 3 dan 2.7.9 untuk Python 2, dan digunakan oleh banyak proyek Python, menjadikannya alat penting untuk programmer Python mana pun.

Instalasi pipa

Pada CentOS 8, Anda dapat menginstal paket dengan perintah dnf atau yum. Tergantung pada versi Python yang kita gunakan, kita dapat menginstal paket pip2 atau pip3 atau kita dapat menginstal kedua paket tanpa masalah.

Instal python2-pip

Pertama, kami memperbarui sistem:

$ sudo yum update

Kami akan menginstal paket python2-pip dan python3-pip.
Pertama, kami menginstal python2-pip:

$ sudo yum -y install python2-pip
Last metadata expiration check: 2:12:46 ago on Tue 01 Oct 2019 01:19:15 PM UTC.
Dependencies resolved.
===============================================================================
 Package           Arch   Version                              Repository
                                                                          Size
===============================================================================
Installing:
 python2-pip       noarch 9.0.3-13.module_el8.0.0+32+017b2cba  AppStream 2.0 M
Installing dependencies:
 python2           x86_64 2.7.15-22.module_el8.0.0+32+017b2cba AppStream 107 k
 python2-libs      x86_64 2.7.15-22.module_el8.0.0+32+017b2cba AppStream 6.0 M
 python2-setuptools
                   noarch 39.0.1-11.module_el8.0.0+32+017b2cba AppStream 643 k
Enabling module streams:
 python27                 2.7                                                 

Transaction Summary
===============================================================================
Install  4 Packages

Total download size: 8.7 M
Installed size: 36 M
Downloading Packages:
(1/4): python2-2.7.15-22.module_el8.0.0+32+017  70 kB/s | 107 kB     00:01    
(2/4): python2-setuptools-39.0.1-11.module_el8 689 kB/s | 643 kB     00:00    
(3/4): python2-pip-9.0.3-13.module_el8.0.0+32+ 777 kB/s | 2.0 MB     00:02    
(4/4): python2-libs-2.7.15-22.module_el8.0.0+3 1.4 MB/s | 6.0 MB     00:04    
-------------------------------------------------------------------------------
Total                                          2.0 MB/s | 8.7 MB     00:04     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                       1/1 
  Installing       : python2-libs-2.7.15-22.module_el8.0.0+32+017b2cba.x   1/4 
  Installing       : python2-pip-9.0.3-13.module_el8.0.0+32+017b2cba.noa   2/4 
  Installing       : python2-setuptools-39.0.1-11.module_el8.0.0+32+017b   3/4 
  Installing       : python2-2.7.15-22.module_el8.0.0+32+017b2cba.x86_64   4/4 
  Running scriptlet: python2-2.7.15-22.module_el8.0.0+32+017b2cba.x86_64   4/4 
  Verifying        : python2-2.7.15-22.module_el8.0.0+32+017b2cba.x86_64   1/4 
  Verifying        : python2-libs-2.7.15-22.module_el8.0.0+32+017b2cba.x   2/4 
  Verifying        : python2-pip-9.0.3-13.module_el8.0.0+32+017b2cba.noa   3/4 
  Verifying        : python2-setuptools-39.0.1-11.module_el8.0.0+32+017b   4/4 

Installed:
  python2-pip-9.0.3-13.module_el8.0.0+32+017b2cba.noarch                       
  python2-2.7.15-22.module_el8.0.0+32+017b2cba.x86_64                          
  python2-libs-2.7.15-22.module_el8.0.0+32+017b2cba.x86_64                     
  python2-setuptools-39.0.1-11.module_el8.0.0+32+017b2cba.noarch               

Complete!

Instal python3-pip

Kami menginstal paket python3-pip dengan cara yang sama:

$ sudo yum -y install python3-pip
CentOS-8 - AppStream                           3.3 kB/s | 4.3 kB     00:01    
CentOS-8 - Base                                1.7 kB/s | 3.8 kB     00:02    
CentOS-8 - Extras                              1.4 kB/s | 1.5 kB     00:01    
Docker CE Stable - x86_64                      3.1 kB/s | 3.5 kB     00:01    
Extra Packages for Enterprise Linux 8 - x86_64  17 kB/s |  32 kB     00:01    
Extra Packages for Enterprise Linux 8 - x86_64 464 kB/s | 1.8 MB     00:04    
Dependencies resolved.
===============================================================================
 Package            Arch   Version                             Repository
                                                                          Size
===============================================================================
Installing:
 python3-pip        noarch 9.0.3-13.el8                        AppStream  18 k
Installing dependencies:
 python36           x86_64 3.6.8-2.module_el8.0.0+33+0a10c0e1  AppStream  19 k
 python3-setuptools noarch 39.2.0-4.el8                        BaseOS    162 k
Enabling module streams:
 python36                  3.6                                                

Transaction Summary
===============================================================================
Install  3 Packages

Total download size: 200 k
Installed size: 466 k
Downloading Packages:
(1/3): python3-pip-9.0.3-13.el8.noarch.rpm      15 kB/s |  18 kB     00:01    
(2/3): python36-3.6.8-2.module_el8.0.0+33+0a10  14 kB/s |  19 kB     00:01    
(3/3): python3-setuptools-39.2.0-4.el8.noarch.  97 kB/s | 162 kB     00:01    
-------------------------------------------------------------------------------
Total                                           70 kB/s | 200 kB     00:02     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                       1/1 
  Installing       : python3-setuptools-39.2.0-4.el8.noarch                1/3 
  Installing       : python36-3.6.8-2.module_el8.0.0+33+0a10c0e1.x86_64    2/3 
  Running scriptlet: python36-3.6.8-2.module_el8.0.0+33+0a10c0e1.x86_64    2/3 
  Installing       : python3-pip-9.0.3-13.el8.noarch                       3/3 
  Running scriptlet: python3-pip-9.0.3-13.el8.noarch                       3/3 
  Verifying        : python3-pip-9.0.3-13.el8.noarch                       1/3 
  Verifying        : python36-3.6.8-2.module_el8.0.0+33+0a10c0e1.x86_64    2/3 
  Verifying        : python3-setuptools-39.2.0-4.el8.noarch                3/3 

Installed:
  python3-pip-9.0.3-13.el8.noarch                                              
  python36-3.6.8-2.module_el8.0.0+33+0a10c0e1.x86_64                           
  python3-setuptools-39.2.0-4.el8.noarch                                       

Complete!

Selanjutnya, kita perlu mengkonfirmasi bahwa instalasi paket berhasil.

Konfirmasi instalasi dengan menanyakan nomor versi

Kami akan menanyakan informasi versi python2-pip dan python3-pip dengan perintah berikut:

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

Untuk python3-pip kami mengetik:

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

Cari paket Python

Misalkan kita ingin menginstal beberapa modul dengan pip, tetapi kita tidak tahu nama modul yang tepat. Kami dapat mencari paket yang tersedia menggunakan kata kunci.

$ pip2 search docker

Atau

$ pip3 search docker
docker (4.0.2)                      - A Python library for the Docker Engine
                                      API.
docker-utils (0.1.4)                - Utilities for Docker
Fifty-Docker (1.1)                  - Docker utilities.
monit-docker (0.0.32)               - monit-docker
docker-deployer (0.1.0)             - A Fabric framework for Docker
                                      deployment based on Docker-Compose.
docker-pid (0.0.3)                  - docker-pid: Listing process IDs in
                                      docker containers.
docker-fabric (0.5.0)               - Build Docker images, and run Docker
                                      containers in Fabric.
morgaroth-docker (0.0.1)            - Morgaroths Docker Client
docker-api (0.1.3)                  - Docker API Client
docker-wrapper (2.1.2)              - Docker Wrapper for Python
docker-registry (0.9.1)             - Registry server for Docker
docker-py (1.10.6)                  - Python client for Docker.
docker-cloud (1.0.9)                - CLI for Docker Cloud
docker-dev (1.0b2)                  - Development tools for Docker
pysecrets-docker (1.0.0)            - Docker secrets to ENV
docker-master (0.0.2)               - An alternative to docker-compose
bonobo-docker (0.6.0)               - Docker extension for Bonobo
colomoto-docker (7.2)               - Helper script to run docker image
                                      colomoto/colomoto-docker
docker-parse (0.5.6)                - Parse docker-run options from a running
                                      Docker container

.....

Daftarnya terus berlanjut, tetapi kita akan menginstal modul docker-fabric pada contoh berikutnya.

Menginstal modul (paket) menggunakan PIP

Kita dapat menginstal paket docker-fiber menggunakan perintah pip sederhana:

$ pip3 install docker-fabric
Collecting docker-fabric
  Downloading https://files.pythonhosted.org/packages/1d/66/2c75e141373dca58ec20ccdbb2b2204a07e02f692c7fc42c83fe98e71bfd/docker-fabric-0.5.0.tar.gz
Requirement already satisfied: six in /usr/lib/python3.6/site-packages (from docker-fabric)
Collecting Fabric>=1.8.0 (from docker-fabric)
  Downloading https://files.pythonhosted.org/packages/d7/cb/47feeb00dae857f0fbd1153a61e902e54ed77ccdc578b371a514a3959a19/fabric-2.5.0-py2.py3-none-any.whl (51kB)
    100% |████████████████████████████████| 61kB 1.3MB/s 
Collecting docker-py>=1.9.0 (from docker-fabric)
  Downloading https://files.pythonhosted.org/packages/23/c7/1fd6d4d620809fe2f323869d719e2dd0086c939b67021303a9ec40f5a05b/docker_py-1.10.6-py2.py3-none-any.whl (50kB)
    100% |████████████████████████████████| 51kB 4.8MB/s 
Collecting docker-map>=0.8.0b2 (from docker-fabric)
  Downloading https://files.pythonhosted.org/packages/c8/31/b23be95ca29113b0af3fc3c931de5f471f3a7e07af0d4ce29d47445dcc07/docker-map-1.0.0.tar.gz (109kB)
    100% |████████████████████████████████| 112kB 2.5MB/s 
Collecting paramiko>=2.4 (from Fabric>=1.8.0->docker-fabric)
  Downloading https://files.pythonhosted.org/packages/4b/80/74dace9e48b0ef923633dfb5e48798f58a168e4734bca8ecfaf839ba051a/paramiko-2.6.0-py2.py3-none-any.whl (199kB)

....

  Running setup.py install for docker-map ... done
  Running setup.py install for docker-fabric ... done
Successfully installed Fabric-2.5.0 bcrypt-3.1.7 certifi-2019.9.11 chardet-3.0.4 cryptography-2.7 docker-fabric-0.5.0 docker-map-1.0.0 docker-py-1.10.6 docker-pycreds-0.4.0 invoke-1.3.0 paramiko-2.6.0 pynacl-1.3.0 requests-2.22.0 urllib3-1.25.6 websocket-client-0.56.0

Daftar paket yang diinstal

Untuk daftar paket yang diinstal, kami menggunakan perintah ini:

$ pip3 list

bcrypt (3.1.7)
certifi (2019.9.11)
cffi (1.11.5)
chardet (3.0.4)
configobj (5.0.6)
cryptography (2.7)
decorator (4.2.1)
docker-fabric (0.5.0)
docker-map (1.0.0)
docker-py (1.10.6)
docker-pycreds (0.4.0)
fabric (2.5.0)
gpg (1.10.0)
idna (2.5)

.....

Untuk daftar paket lama, ketik:

$ pip2 list --outdated
pip (9.0.3) - Latest: 19.2.3 [wheel]
setuptools (39.0.1) - Latest: 41.2.0 [wheel]

Hapus modul (paket) menggunakan PIP

Satu-satunya hal yang dapat dilihat dalam tutorial ini adalah cara menghapus paket pip. Ini cukup sederhana, kami mengetik:

$ pip3 uninstall docker-fabric
Uninstalling docker-fabric-0.5.0:
  /usr/local/lib/python3.6/site-packages/docker_fabric-0.5.0-py3.6.egg-info
  /usr/local/lib/python3.6/site-packages/dockerfabric/__init__.py
  /usr/local/lib/python3.6/site-packages/dockerfabric/__pycache__/__init__.cpython-36.pyc
  /usr/local/lib/python3.6/site-packages/dockerfabric/__pycache__/actions.cpython-36.pyc
  /usr/local/lib/python3.6/site-packages/dockerfabric/__pycache__/api.cpython-36.pyc
  /usr/local/lib/python3.6/site-packages/dockerfabric/__pycache__/apiclient.cpython-36.pyc

.....

  /usr/local/lib/python3.6/site-packages/dockerfabric/utils/output.py
  /usr/local/lib/python3.6/site-packages/dockerfabric/utils/users.py
  /usr/local/lib/python3.6/site-packages/dockerfabric/yaml.py
Proceed (y/n)? y

Daftar file yang akan dihapus akan ditampilkan. Ketika kita melanjutkan dengan mengetik y, paket akan dihapus.

Proceed (y/n)? y
  Successfully uninstalled docker-fabric-0.5.0

Hasil

Anda telah berhasil menginstal pip pada sistem CentOS 8 Anda dan mempelajari cara mudah menginstal dan menghapus modul python dengan pip. Untuk informasi lebih lanjut, Anda dapat memeriksa panduan pengguna pip. Jika Anda memiliki pertanyaan atau umpan balik, komentar di bawah.

Baca juga:

[ad_2]

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *